我正在努力让这个简单的 f-ty 工作......我的情况是:
- 获取当前网址
- 修改它
- 导航/重定向到它
- 在那里执行自定义 JS 代码
我遇到的最大问题是 4)
清单.json
{
"name": "Hello, World!",
"description": "Navigate and execute custom js script",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"tabs",
"activeTab",
"scripting"
],
"background": {
"service_worker": "background.js"
},
"action": {}
}
背景.js
function myCustomScript() {
alert('myCustomScript test ok!');
console.log('myCustomScript test ok!');
}
chrome.action.onClicked.addListener((tab) => {
chrome.tabs.update({url: "https://example.com"}, myCustomScript);
});
页面被重定向但我的 js 函数没有执行!你知道为什么以及如何解决它吗?
PS:这是我第一次创建我的 chrome 扩展,也许我做错了什么......