【发布时间】:2021-01-09 06:48:24
【问题描述】:
更新:
因此,由于我的文件夹的结构方式,它看起来应该是 chrome-extension://meajimhgfmioppbkoppphhkbcmapfngh/html/index.html 而不是 chrome-extension://meajimhgfmioppbkoppphhkbcmapfngh/index.html。当我在搜索栏中手动输入它时,它可以工作,但是当我将代码更新为此时仍然无法工作:
chrome.contextMenus.onClicked.addListener(function (result) {
if (result['menuItemId'] === 'open-sesame') {
chrome.tabs.create({ 'url': chrome.extension.getURL("/html/index.html") }, function (tab) {
})
}
})
我有一个 chrome 扩展程序,用户可以在其中将我的扩展程序作为新标签显示。我正在实施的一项新功能是能够切换回默认的谷歌搜索页面,现在用户可以从浏览器操作上下文菜单访问扩展。我在尝试提出解决方案时引用了this answer。
我现在卡在 contextMenu 上,因为当我单击它时,我来到显示无法访问文件的页面。
background.js
chrome.contextMenus.create({
title: "Open",
contexts: ['browser_action'],
id: 'open-sesame',
})
chrome.contextMenus.onClicked.addListener(function (result) {
if (result['menuItemId'] === 'open-sesame') {
chrome.tabs.create({ 'url': chrome.extension.getURL("index.html") }, function (tab) {
})
}
})
新标签打开的网址是chrome-extension://meajimhgfmioppbkoppphhkbcmapfngh/index.html,打开我的扩展似乎是正确的,但无论出于何种原因它仍然无法正常工作。
Folder Structure
html
- index.html
js
- background.js
css
- style.css
【问题讨论】:
-
听起来你的扩展没有
index.html。
标签: javascript google-chrome google-chrome-extension