在 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://*/*
但没有成功。
有什么办法吗?或者有没有其他方法可以自动单击另一个正在运行的扩展程序中的按钮?
谢谢!