0

From within a Chrome extension, is there any way I can execute a script into another open extension? I just want to click a specific button whenever a different extension opens.

I tried using chrome scripting APIs:

chrome.scripting.executeScript({
   target: { tabId: tab.id }, // tab id relative the other open extension
   function: injectIntoAnotherExtension
});

function injectIntoAnotherExtension() {
    document.getElementById('some-button').click();
}

At first I got the error:

Error: Cannot access a chrome-extension:// URL of different extension

After enabling the Extensions on chrome:// URLs flag (chrome://flags/#extensions-on-chrome-urls), I now get:

Error: Cannot access contents of url "chrome-extension://foo/bar/xyz.html". Extension manifest must request permission to access this host.

Here are my manifest permissions, which should allow all urls:

"host_permissions": [
   "<all-urls>"
]

I also tried with *://*/* or chrome-extensions://*/* but with no success.

Related questions: this and this.

Any way around it? Or is there any other way to automatically click a button in another running extension?

Thanks!

2
  • 1
    Either use chrome.debugger API (can be used to automate access) or write a devtools panel where you will use chrome.devtools.inspectedWindow.eval while devtools is open on that extension's page and your panel is selected. Commented Nov 8, 2021 at 8:44
  • Thanks, it worked with chrome.debugger APIs! Commented Nov 8, 2021 at 13:46

1 Answer 1

1

Thanks to @wOxxOm, I got it working with:

chrome.debugger.attach({
   tabId: tab.id
}, '1.0', function() {
   chrome.debugger.sendCommand({
      tabId: tab.id
   }, "Runtime.evaluate", { expression: 
      "document.getElementById('some-button').click();" 
   }, function(response) {
      console.log(response);
   });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.