我收到“没有匹配的签名”我的background.js 中出现错误
我收到错误“Uncaught TypeError:调用 scripting.executeScript 时出错(scripting.ScriptInjection 注入,可选函数回调):没有匹配的签名。”在我的控制台中。 我不知道出了什么问题,请有人帮助我,我真的很感激。
这是background.js 代码:
var Tabclicked = false;
disableBrowserAction();
function disableBrowserAction(tabId) {
chrome.scripting.executeScript(tabId, { file: 'jquery.js' }, function() {
chrome.scripting.executeScript(tabId, { file: 'CloseRuler.js' });
});
}
function enableBrowserAction(tabId) {
chrome.scripting.executeScript(tabId, { file: 'jquery.js' }, function() {
chrome.scripting.executeScript(tabId, { files: 'Ruler.js' });
});
}
function updateState() {
if (Tabclicked == false) {
Tabclicked = true;
enableBrowserAction();
} else {
Tabclicked = false;
disableBrowserAction();
}
}
//chrome.pageAction.onClicked.addListener(updateState);
chrome.action.onClicked.addListener(function(tabId) {
updateState(tabId);
alert('File test alert');
});
alert('File test alert');
这是我的清单:
{
"name": "Physics Ruler",
"description": "Position the ruler and measure the objects!",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"activeTab",
"scripting"
],
"background": {
"service_worker": "background.js",
"type": "module"
},
"action": {
"default_icon": "icon.png",
"default_title": "Ruler",
"name": "Physics Ruler"
},
"content_scripts": [{
"js": ["jquery.js"],
"matches": ["*://*/*"]
}],
"host_permissions": [
"*://*/*"
]
}
I get the error "Uncaught TypeError: Error in invocation of scripting.executeScript(scripting.ScriptInjection injection, optional function callback): No matching signature." in my console.
I have no idea what's wrong, someone please help me, I really appreciate it.
Here is the background.js code:
var Tabclicked = false;
disableBrowserAction();
function disableBrowserAction(tabId) {
chrome.scripting.executeScript(tabId, { file: 'jquery.js' }, function() {
chrome.scripting.executeScript(tabId, { file: 'CloseRuler.js' });
});
}
function enableBrowserAction(tabId) {
chrome.scripting.executeScript(tabId, { file: 'jquery.js' }, function() {
chrome.scripting.executeScript(tabId, { files: 'Ruler.js' });
});
}
function updateState() {
if (Tabclicked == false) {
Tabclicked = true;
enableBrowserAction();
} else {
Tabclicked = false;
disableBrowserAction();
}
}
//chrome.pageAction.onClicked.addListener(updateState);
chrome.action.onClicked.addListener(function(tabId) {
updateState(tabId);
alert('File test alert');
});
alert('File test alert');
Here is my manifest:
{
"name": "Physics Ruler",
"description": "Position the ruler and measure the objects!",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"activeTab",
"scripting"
],
"background": {
"service_worker": "background.js",
"type": "module"
},
"action": {
"default_icon": "icon.png",
"default_title": "Ruler",
"name": "Physics Ruler"
},
"content_scripts": [{
"js": ["jquery.js"],
"matches": ["*://*/*"]
}],
"host_permissions": [
"*://*/*"
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,我找到了答案,并且文档有点无帮助,我只是尝试了不同的方法,直到它起作用。
我们必须使用 chrome tabs 来实现这个函数:
在该函数中我们可以使用“tabs[0].id”来获取 id。
例如:
}
So, I have found the answer, and the documentation was kind of not help full, I have just tried different things until it worked.
We have to make this function with chrome tabs:
in that function then we can use "tabs[0].id" to get the id.
for example:
}