我最近发现了chrome 扩展开发并被runtime.excuteScript方法卡住了,第三个参数中的回调系统地返回了一个空对象......
为简洁起见,我将省去我所有的 manifest.json(v2):
▼清单权限:
"permissions": [
"storage",
"cookies",
"tabs",
"background",
"activeTab",
"<all_urls>",
"*://*/*"
]
▼ manifest content-script:
"content_scripts": [
{
"matches": ["<all_urls>"],
"run_at": "document_end",
"js": ["js/content-script.js"]
}
]
我的目标是将 localStorage 的内容发送到我的扩展程序。
▼弹窗.js:
chrome.tabs.executeScript(
null,
{ file: "js/content-script.js" },
(result) => {
if(result) console.log( " Result of content-script:",result )
else console.log(" No content-script, no result")
}
);
▼内容-script.js:
localStorage;
▼扩展控制台输出:
Result of content-script: Array(1)
▶︎ 0: {}
length:1
▶︎ __proto__: Array(0)
请向我解释这个错误,让这个夜晚变得美好!谢谢!