沙盒页
This commit is contained in:
parent
29ce09a35d
commit
c8a5430594
@ -24,6 +24,7 @@ export default defineConfig({
|
||||
context: __dirname,
|
||||
entry: {
|
||||
service_worker: `${src}/service_worker.ts`,
|
||||
offscreen: `${src}/offscreen.ts`,
|
||||
sandbox: `${src}/sandbox.ts`,
|
||||
popup: `${src}/pages/popup/main.tsx`,
|
||||
},
|
||||
@ -105,6 +106,13 @@ export default defineConfig({
|
||||
minify: true,
|
||||
chunks: ["popup"],
|
||||
}),
|
||||
new rspack.HtmlRspackPlugin({
|
||||
filename: `${dist}/ext/src/offscreen.html`,
|
||||
template: `${src}/pages/offscreen.html`,
|
||||
inject: "head",
|
||||
minify: true,
|
||||
chunks: ["offscreen"],
|
||||
}),
|
||||
new rspack.HtmlRspackPlugin({
|
||||
filename: `${dist}/ext/src/sandbox.html`,
|
||||
template: `${src}/pages/sandbox.html`,
|
||||
|
@ -22,7 +22,7 @@
|
||||
],
|
||||
"sandbox": {
|
||||
"pages": [
|
||||
"sandbox.html"
|
||||
"src/sandbox.html"
|
||||
]
|
||||
}
|
||||
}
|
0
src/offscreen.ts
Normal file
0
src/offscreen.ts
Normal file
12
src/pages/offscreen.html
Normal file
12
src/pages/offscreen.html
Normal file
@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Offscreen</title>
|
||||
</head>
|
||||
<body>
|
||||
<iframe src="/src/sandbox.html" name="sandbox" style="display: none"></iframe>
|
||||
</body>
|
||||
</html>
|
@ -1,3 +1 @@
|
||||
chrome.runtime.onMessage.addListener((data) => {
|
||||
console.log(data);
|
||||
});
|
||||
eval('console.log("Hello from sandbox!");');
|
||||
|
@ -1,12 +1,13 @@
|
||||
|
||||
|
||||
chrome.runtime.onConnect.addListener((port) => {
|
||||
console.log("service worker connected", port);
|
||||
});
|
||||
|
||||
async function setupOffscreenDocument() {
|
||||
// 创建运行后台脚本的沙盒环境
|
||||
await chrome.offscreen.createDocument({
|
||||
url: "src/sandbox.html",
|
||||
reasons: [chrome.offscreen.Reason.DOM_SCRAPING],
|
||||
justification: "background script",
|
||||
url: "src/offscreen.html",
|
||||
reasons: [chrome.offscreen.Reason.CLIPBOARD],
|
||||
justification: "offscreen page",
|
||||
});
|
||||
|
||||
// Send message to offscreen document
|
||||
|
Loading…
x
Reference in New Issue
Block a user