本文主要是介绍chrome扩展点击图标通过后台代码使用编程的方式显示侧边栏,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
manifest.json:
{"manifest_version": 3,"name": "ChatGPT学习","version": "0.0.6","description": "欢迎加入我们一起学习ChatGPT","icons": {"16": "./src/images/logo.png","48": "./src/images/logo.png","128": "./src/images/logo.png"},"side_panel": {"default_path": "./src/views/panel.html"},"permissions": ["sidePanel"],"action": {"default_title": "点击打开ChatGPT学习侧边栏"},"background": {"service_worker": "./src/scripts/service-worker.js"},"content_scripts": [{"matches": ["http://*/*", "https://*/*"],"exclude_matches": ["https://chat.xutongbao.top/*","http://localhost:*/*"],"css": ["./dist/lib/layui.css", "./dist/css/app.css"],"js": ["./dist/lib/layui.js", "./dist/js/app.js", "./index.js"]}],"content_security_policy": {"extension_pages": "script-src 'self'; object-src 'self';"}
}
./src/scripts/service-worker.js:
// chrome.sidePanel
// .setPanelBehavior({ openPanelOnActionClick: true })
// .catch((error) => console.error(error))chrome.action.onClicked.addListener((tab) => {// 当扩展图标被点击时,执行下面的代码console.log('扩展图标被点击了!')chrome.sidePanel.open({ windowId: tab.windowId });
})console.log(1)
人工智能学习网站:
https://chat.xutongbao.top
这篇关于chrome扩展点击图标通过后台代码使用编程的方式显示侧边栏的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!