[英]Chrome Extension Create a Tab and inject content into it
Hi I'm trying to create a new tab in my background script, and inject a script (for now its just a regular alert to check the code), but I cant manage to do that since CSP is blocked if I try inline script and content scripts cant be injected into the chrome-extensions:// scheme.嗨,我正在尝试在我的后台脚本中创建一个新选项卡,并注入一个脚本(现在它只是一个检查代码的常规警报),但我无法做到这一点,因为如果我尝试内联脚本和内容脚本不能注入到 chrome-extensions:// 方案中。
my manifest:我的清单:
{
"manifest_version": 3,
"name": "OSINTisizer",
"description": "OSINT any IP or URL",
"version": "1.20",
"icons": {
"48": "images/logo_48.png",
"128": "images/logo_128.png"
},
"background": {
"service_worker": "background.js"
},
"permissions": [
"contextMenus",
"background",
"scripting",
"tabs",
"storage",
"activeTab"
],
"host_permissions": [
"*://*/*"
]
}
My background.js code snippet that is relevant:我的 background.js 代码片段是相关的:
chrome.tabs.create({ url: 'report.html' });
});
I'd like the report.js code to be injected into the newly created tab under:我希望将 report.js 代码注入到新创建的选项卡中:
chrome-extensions://foobar/report.html chrome-extensions://foobar/report.html
UPDATE: Trying to do this task using chrome.scripting.executeScript on the newly created tab but still not wroking更新:尝试在新创建的选项卡上使用 chrome.scripting.executeScript 执行此任务,但仍无法正常工作
chrome.tabs.create({ url: "report.html" }, function (createdTab) {
chrome.scripting.executeScript({
target: { tabId: createdTab },
files: ["report.js"],
});
});
Solved:!解决了:! For some reason the CSP blocked me the previous time I tried to do that but the code that worked is :
出于某种原因,CSP 在我上次尝试这样做时阻止了我,但有效的代码是:
chrome.storage.local.set({ info: uniqeEmails }, function () {});
chrome.tabs.create({ url: "report.html" },{
<!DOCTYPE html>
<html>
<head>
<script src="report.js"></script>
</head>
<body>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.