处理 gm add element csp问题
This commit is contained in:
@ -60,9 +60,7 @@ export default class ContentRuntime {
|
||||
parentNode = (this.msg as CustomEventMessage).getAndDelRelatedTarget(parentNodeId);
|
||||
}
|
||||
const el = <Element>document.createElement(tagName);
|
||||
Object.keys(attr).forEach((key) => {
|
||||
el.setAttribute(key, attr[key]);
|
||||
});
|
||||
|
||||
let textContent = "";
|
||||
if (attr) {
|
||||
if (attr.textContent) {
|
||||
@ -72,6 +70,9 @@ export default class ContentRuntime {
|
||||
} else {
|
||||
attr = {};
|
||||
}
|
||||
Object.keys(attr).forEach((key) => {
|
||||
el.setAttribute(key, attr[key]);
|
||||
});
|
||||
if (textContent) {
|
||||
el.innerHTML = textContent;
|
||||
}
|
||||
|
@ -247,6 +247,10 @@ export class RuntimeService {
|
||||
registerInjectScript() {
|
||||
chrome.userScripts.getScripts({ ids: ["scriptcat-inject"] }).then((res) => {
|
||||
if (res.length == 0) {
|
||||
chrome.userScripts.configureWorld({
|
||||
csp: "script-src 'self' 'unsafe-inline' 'unsafe-eval' *",
|
||||
messaging: true,
|
||||
});
|
||||
fetch("inject.js")
|
||||
.then((res) => res.text())
|
||||
.then(async (injectJs) => {
|
||||
@ -261,18 +265,17 @@ export class RuntimeService {
|
||||
world: "MAIN",
|
||||
runAt: "document_start",
|
||||
},
|
||||
// 注册content
|
||||
{
|
||||
id: "scriptcat-content",
|
||||
js: [{ file: "src/content.js" }],
|
||||
matches: ["<all_urls>"],
|
||||
allFrames: true,
|
||||
runAt: "document_start",
|
||||
world: "USER_SCRIPT",
|
||||
},
|
||||
]);
|
||||
});
|
||||
chrome.scripting.registerContentScripts([
|
||||
{
|
||||
id: "scriptcat-content",
|
||||
js: ["src/content.js"],
|
||||
matches: ["<all_urls>"],
|
||||
allFrames: true,
|
||||
runAt: "document_start",
|
||||
world: "ISOLATED",
|
||||
},
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -426,7 +429,6 @@ export class RuntimeService {
|
||||
if (script.metadata["run-at"]) {
|
||||
registerScript.runAt = getRunAt(script.metadata["run-at"]);
|
||||
}
|
||||
console.log("registerScript", script.name, registerScript, scriptMatchInfo);
|
||||
if (await Cache.getInstance().get("registryScript:" + script.uuid)) {
|
||||
await chrome.userScripts.update([registerScript]);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user