Content Script only sees original DOM












0















I am working on creating a content script which provides live information next to a continuously changing page.



I have created a block of code which is executed every 3 seconds(not final pattern yet), and gathers data based on the current DOM, and injects information next to it.



The problem, the only DOM the script can see is the original one that was loaded at the point of 'document_idle', and changes after that point are not visible to my script.



Is there a way for my script to see the current DOM at any point in time?



manifest.json



{
"name": "Info Injector",
"version": "1.0",
"description": "Shows info",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://*.boardgamearena.com/cantstop?*"],
"js": ["contentScript.js"]
}
]}


contentScript.js



  window.setInterval(function(){
var e = window.document.getElementsByTagName("script")[16];
//console.log("e", e);

var tokens = e.innerHTML.substring(e.innerHTML.indexOf("tokens":")+8, e.innerHTML.indexOf(""wincolumns"")-1);
console.log("tokens", tokens);
}, 3000);









share|improve this question

























  • Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a Minimal, Complete, and Verifiable example of your attempt, noting input and expected output.

    – mplungjan
    Nov 20 '18 at 16:17











  • Might need to see some code (content script) and your manifest

    – epascarello
    Nov 20 '18 at 16:18













  • Added manifest and contentScript. the 'e' variable does not change between moves in the game, which the "tokens" value represents. It only changes when the page is refreshed.

    – Nathan Werry
    Nov 20 '18 at 16:32











  • The variables change in memory without changing the original script text. Depending on the page script, you might be able to extract the live data by running a page-level script (example1, example2).

    – wOxxOm
    Nov 20 '18 at 16:45











  • I added the code block below to the content script to inject the whole script into the page, but I get the same results. And I am not able to see the script when I "view page source", should I see it in there? function runInPage(fn) { const script = document.createElement('script'); document.head.appendChild(script).text = '((...args) => (' + fn + ')(...args))(' + JSON.stringify(chrome.runtime.id) + ')'; script.remove(); }

    – Nathan Werry
    Nov 22 '18 at 16:48
















0















I am working on creating a content script which provides live information next to a continuously changing page.



I have created a block of code which is executed every 3 seconds(not final pattern yet), and gathers data based on the current DOM, and injects information next to it.



The problem, the only DOM the script can see is the original one that was loaded at the point of 'document_idle', and changes after that point are not visible to my script.



Is there a way for my script to see the current DOM at any point in time?



manifest.json



{
"name": "Info Injector",
"version": "1.0",
"description": "Shows info",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://*.boardgamearena.com/cantstop?*"],
"js": ["contentScript.js"]
}
]}


contentScript.js



  window.setInterval(function(){
var e = window.document.getElementsByTagName("script")[16];
//console.log("e", e);

var tokens = e.innerHTML.substring(e.innerHTML.indexOf("tokens":")+8, e.innerHTML.indexOf(""wincolumns"")-1);
console.log("tokens", tokens);
}, 3000);









share|improve this question

























  • Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a Minimal, Complete, and Verifiable example of your attempt, noting input and expected output.

    – mplungjan
    Nov 20 '18 at 16:17











  • Might need to see some code (content script) and your manifest

    – epascarello
    Nov 20 '18 at 16:18













  • Added manifest and contentScript. the 'e' variable does not change between moves in the game, which the "tokens" value represents. It only changes when the page is refreshed.

    – Nathan Werry
    Nov 20 '18 at 16:32











  • The variables change in memory without changing the original script text. Depending on the page script, you might be able to extract the live data by running a page-level script (example1, example2).

    – wOxxOm
    Nov 20 '18 at 16:45











  • I added the code block below to the content script to inject the whole script into the page, but I get the same results. And I am not able to see the script when I "view page source", should I see it in there? function runInPage(fn) { const script = document.createElement('script'); document.head.appendChild(script).text = '((...args) => (' + fn + ')(...args))(' + JSON.stringify(chrome.runtime.id) + ')'; script.remove(); }

    – Nathan Werry
    Nov 22 '18 at 16:48














0












0








0








I am working on creating a content script which provides live information next to a continuously changing page.



I have created a block of code which is executed every 3 seconds(not final pattern yet), and gathers data based on the current DOM, and injects information next to it.



The problem, the only DOM the script can see is the original one that was loaded at the point of 'document_idle', and changes after that point are not visible to my script.



Is there a way for my script to see the current DOM at any point in time?



manifest.json



{
"name": "Info Injector",
"version": "1.0",
"description": "Shows info",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://*.boardgamearena.com/cantstop?*"],
"js": ["contentScript.js"]
}
]}


contentScript.js



  window.setInterval(function(){
var e = window.document.getElementsByTagName("script")[16];
//console.log("e", e);

var tokens = e.innerHTML.substring(e.innerHTML.indexOf("tokens":")+8, e.innerHTML.indexOf(""wincolumns"")-1);
console.log("tokens", tokens);
}, 3000);









share|improve this question
















I am working on creating a content script which provides live information next to a continuously changing page.



I have created a block of code which is executed every 3 seconds(not final pattern yet), and gathers data based on the current DOM, and injects information next to it.



The problem, the only DOM the script can see is the original one that was loaded at the point of 'document_idle', and changes after that point are not visible to my script.



Is there a way for my script to see the current DOM at any point in time?



manifest.json



{
"name": "Info Injector",
"version": "1.0",
"description": "Shows info",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://*.boardgamearena.com/cantstop?*"],
"js": ["contentScript.js"]
}
]}


contentScript.js



  window.setInterval(function(){
var e = window.document.getElementsByTagName("script")[16];
//console.log("e", e);

var tokens = e.innerHTML.substring(e.innerHTML.indexOf("tokens":")+8, e.innerHTML.indexOf(""wincolumns"")-1);
console.log("tokens", tokens);
}, 3000);






javascript google-chrome-extension






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 16:28







Nathan Werry

















asked Nov 20 '18 at 16:14









Nathan WerryNathan Werry

834517




834517













  • Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a Minimal, Complete, and Verifiable example of your attempt, noting input and expected output.

    – mplungjan
    Nov 20 '18 at 16:17











  • Might need to see some code (content script) and your manifest

    – epascarello
    Nov 20 '18 at 16:18













  • Added manifest and contentScript. the 'e' variable does not change between moves in the game, which the "tokens" value represents. It only changes when the page is refreshed.

    – Nathan Werry
    Nov 20 '18 at 16:32











  • The variables change in memory without changing the original script text. Depending on the page script, you might be able to extract the live data by running a page-level script (example1, example2).

    – wOxxOm
    Nov 20 '18 at 16:45











  • I added the code block below to the content script to inject the whole script into the page, but I get the same results. And I am not able to see the script when I "view page source", should I see it in there? function runInPage(fn) { const script = document.createElement('script'); document.head.appendChild(script).text = '((...args) => (' + fn + ')(...args))(' + JSON.stringify(chrome.runtime.id) + ')'; script.remove(); }

    – Nathan Werry
    Nov 22 '18 at 16:48



















  • Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a Minimal, Complete, and Verifiable example of your attempt, noting input and expected output.

    – mplungjan
    Nov 20 '18 at 16:17











  • Might need to see some code (content script) and your manifest

    – epascarello
    Nov 20 '18 at 16:18













  • Added manifest and contentScript. the 'e' variable does not change between moves in the game, which the "tokens" value represents. It only changes when the page is refreshed.

    – Nathan Werry
    Nov 20 '18 at 16:32











  • The variables change in memory without changing the original script text. Depending on the page script, you might be able to extract the live data by running a page-level script (example1, example2).

    – wOxxOm
    Nov 20 '18 at 16:45











  • I added the code block below to the content script to inject the whole script into the page, but I get the same results. And I am not able to see the script when I "view page source", should I see it in there? function runInPage(fn) { const script = document.createElement('script'); document.head.appendChild(script).text = '((...args) => (' + fn + ')(...args))(' + JSON.stringify(chrome.runtime.id) + ')'; script.remove(); }

    – Nathan Werry
    Nov 22 '18 at 16:48

















Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a Minimal, Complete, and Verifiable example of your attempt, noting input and expected output.

– mplungjan
Nov 20 '18 at 16:17





Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a Minimal, Complete, and Verifiable example of your attempt, noting input and expected output.

– mplungjan
Nov 20 '18 at 16:17













Might need to see some code (content script) and your manifest

– epascarello
Nov 20 '18 at 16:18







Might need to see some code (content script) and your manifest

– epascarello
Nov 20 '18 at 16:18















Added manifest and contentScript. the 'e' variable does not change between moves in the game, which the "tokens" value represents. It only changes when the page is refreshed.

– Nathan Werry
Nov 20 '18 at 16:32





Added manifest and contentScript. the 'e' variable does not change between moves in the game, which the "tokens" value represents. It only changes when the page is refreshed.

– Nathan Werry
Nov 20 '18 at 16:32













The variables change in memory without changing the original script text. Depending on the page script, you might be able to extract the live data by running a page-level script (example1, example2).

– wOxxOm
Nov 20 '18 at 16:45





The variables change in memory without changing the original script text. Depending on the page script, you might be able to extract the live data by running a page-level script (example1, example2).

– wOxxOm
Nov 20 '18 at 16:45













I added the code block below to the content script to inject the whole script into the page, but I get the same results. And I am not able to see the script when I "view page source", should I see it in there? function runInPage(fn) { const script = document.createElement('script'); document.head.appendChild(script).text = '((...args) => (' + fn + ')(...args))(' + JSON.stringify(chrome.runtime.id) + ')'; script.remove(); }

– Nathan Werry
Nov 22 '18 at 16:48





I added the code block below to the content script to inject the whole script into the page, but I get the same results. And I am not able to see the script when I "view page source", should I see it in there? function runInPage(fn) { const script = document.createElement('script'); document.head.appendChild(script).text = '((...args) => (' + fn + ')(...args))(' + JSON.stringify(chrome.runtime.id) + ')'; script.remove(); }

– Nathan Werry
Nov 22 '18 at 16:48












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397140%2fcontent-script-only-sees-original-dom%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397140%2fcontent-script-only-sees-original-dom%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud