0

在 Chrome 扩展中,有什么方法可以将脚本执行到另一个打开的扩展中?每当打开不同的扩展程序时,我只想单击特定按钮。

我尝试使用chrome 脚本 API

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

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

起初我得到了错误:

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

启用chrome:// URLs标志 ( chrome://flags/#extensions-on-chrome-urls) 上的扩展后,我现在得到:

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

这是我的清单权限,应该允许所有网址:

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

我也尝试过*://*/*chrome-extensions://*/*但没有成功。

相关问题:thisthis

有什么办法吗?或者有没有其他方法可以自动单击另一个正在运行的扩展程序中的按钮?

谢谢!

4

1 回答 1

0

感谢@wOxxOm,我得到了它:

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);
   });
});
于 2021-11-08T13:50:17.083 回答