在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.下面是我的清单权限,它应该允许所有urls:
"host_permissions": [
"<all-urls>"
]我也尝试了*://*/*或chrome-extensions://*/*,但没有成功。
有办法绕过吗?或者是否有其他方法可以自动单击另一个正在运行的扩展中的按钮?
谢谢!
发布于 2021-11-08 13:50:17
多亏了@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);
});
});https://stackoverflow.com/questions/69874853
复制相似问题