Content Script only sees original DOM
up vote
0
down vote
favorite
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
add a comment |
up vote
0
down vote
favorite
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
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 at 16:17
Might need to see some code (content script) and your manifest
– epascarello
Nov 20 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 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 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 at 16:48
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
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
javascript google-chrome-extension
edited Nov 20 at 16:28
asked Nov 20 at 16:14
Nathan Werry
833317
833317
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 at 16:17
Might need to see some code (content script) and your manifest
– epascarello
Nov 20 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 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 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 at 16:48
add a comment |
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 at 16:17
Might need to see some code (content script) and your manifest
– epascarello
Nov 20 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 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 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 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 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 at 16:17
Might need to see some code (content script) and your manifest
– epascarello
Nov 20 at 16:18
Might need to see some code (content script) and your manifest
– epascarello
Nov 20 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 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 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 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 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 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 at 16:48
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 at 16:17
Might need to see some code (content script) and your manifest
– epascarello
Nov 20 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 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 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 at 16:48