1

I am getting confused with Chrome Extension devtools_page. I want to send a command to the current websites Namespace and retrieve information from that page.

devtools_page JS file

//hey webpage, I know you have the Namespace ABC with the method collectData

webpage

let data = ABC.collectData;
return data;

devtools

// I got the data

Where do I add the communication in the extension to be able to get these data. In the manifest I have "content_scripts" with "document_start" And I have "web_accessible-resource" and the JS file from the "devtools_page".

And how do I instantiate the communication?

I tried so many different things and did not manage to get the communication up and running.

My best try was to use chrome.tabs.executeScript, but I cannot access the Namespace.

This is what I have so far:

a) executeScript

chrome.tabs.executeScript({
    code: 'console.log("foo"); return true;
}, function(results) {
    console.log(results[0]);
});

Result: Unchecked runtime.lastError: Cannot access contents of url "devtools://devtools/bundled/devtools_app.html?remoteBase=https://chrome-devtools-frontend.appspot.com/serve_file/@326d148b9655369b86498d9ecca39f63dd2bdd2d/&can_dock=true&dockSide=undocked". Extension manifest must request permission to access this host.

b) devtools.inspectedWindow.eval

chrome.devtools.inspectedWindow.eval(
    "ABC.AllItems.all",
    function(result, isException) {
        if (isException)
            //==> I am getting here
    }
);

Result: Object reference chain is too long

Any help is appreciated.

Dinkheller
  • 4,631
  • 5
  • 39
  • 67
  • Instead of content scripts use chrome.devtools.inspectedWindow.eval, [info](https://developer.chrome.com/extensions/devtools_inspectedWindow). If you still want a content script then you need to dig a level deeper, see [page context](/a/9517879). – wOxxOm Jun 25 '20 at 13:36
  • thanks a lot, but it throws `Object reference chain is too long` – Dinkheller Jun 25 '20 at 13:53
  • @wOxxOm I am trying to get all elements from a webpage - `Ext.ComponentManager.all` - into a custom view inside the chrome dev tools. I created a view (`chrome.devtools.panels.create`) and I am trying to communicate with the ExtJS webpage. I want to create an inspector for ExtJS. – Dinkheller Jun 25 '20 at 18:28
  • Since this is inter-process communication you can't pass DOM elements. Only simple data. – wOxxOm Jun 25 '20 at 18:30
  • I am only passing a huge JSON – Dinkheller Jun 25 '20 at 19:27
  • Sounds like it may have circular references in which case it's not a JSON. Or maybe there's a bug in the API. Try passing JSON.stringify(ABC.AllItems.all) – wOxxOm Jun 26 '20 at 02:51

0 Answers0