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);
Nathan Werry
  • 876
  • 7
  • 18
  • Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] 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](https://stackoverflow.com/a/46941198), [example2](https://stackoverflow.com/a/46870005)). – 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 Answers0