提问人:Piyush 提问时间:2/15/2023 更新时间:2/15/2023 访问量:35
当用户导航到特定站点时显示弹出窗口
Show popup when user navigates to a particular site
问:
我正在尝试创建一个 Chrome 扩展程序,当用户导航到特定站点时,它会在侧面自动生成一个小弹出窗口。
我浏览了Chrome开发者页面上的文档并按照教程进行了操作,但我不确定如何在用户访问特定站点时注入脚本。我希望弹出窗口仅显示在该特定站点上。事实上,我在background.json的 addListener 部分中看不到任何控制台日志
manifest.json
{
"name": "Google helper",
"version": "1.0",
"manifest_version": 3,
"description": "Shows you additional information on google",
"icons": {
"128": "icon128.png"
},
"action": {
"default_icon": {
"128": "icon128.png"
},
"default_title": "Google helper",
"default_popup": "popup.html"
},
"background": {
"service_worker": "background.js"
},
"permissions": [
"tabs",
"activeTab",
"scripting"
// ,
// "https://google.com/"
]
}
背景:.js
// Register the service worker
console.log("Here in background.js before anything starts"); // Able to see this log in service worker view
// Called when the user clicks on the action.
chrome.action.onClicked.addListener(function(tab) {
// No tabs or host permissions needed!
console.log('Turning ' + tab.url + ' red!'); // Don't see this in logs
chrome.scripting.executeScript({
code: 'document.body.style.backgroundColor="red"'
});
});
答: 暂无答案
评论
background
permissions
action