JavaScript class 覆盖所有帧
JavaScript class override for all frames
如果注入的 JavaScript 代码修改 Date
class
Date = new Proxy(Date, { ...
或
Date.prototype.toString = function() { ...
在 window/document 的顶层,这些覆盖更改是否也递归地应用于所有框架和 iframe?
如果不行,有没有办法强制执行?
不行,而且不修改浏览器的源代码也没有办法自动完成。
您必须 运行 使用以下方法之一明确地在每一帧中编写代码:
声明每帧 运行 的内容脚本:
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"],
"run_at": "document_start",
"all_frames": true,
"match_about_blank": true
}],
或在chrome.tabs.executeScript的选项中添加allFrames: true, matchAboutBlank: true
。
或使用核选项:chrome.debugger API to attach to the tab and send a CDP command like Page.addScriptToEvaluateOnNewDocument。缺点是它会在每个选项卡顶部显示警告通知。
在案例 1 和案例 2 中覆盖原型的代码 should be added in page context。另请注意,由于错误或固有限制,Chrome/Firefox 可能无法 运行 某些 iframe 中的内容脚本,例如 Firefox 中带有 CSP sandbox
的 iframe 或 Firefox 中带有 src="javascript:..."
的 iframe Chrome.
如果注入的 JavaScript 代码修改 Date
class
Date = new Proxy(Date, { ...
或
Date.prototype.toString = function() { ...
在 window/document 的顶层,这些覆盖更改是否也递归地应用于所有框架和 iframe?
如果不行,有没有办法强制执行?
不行,而且不修改浏览器的源代码也没有办法自动完成。
您必须 运行 使用以下方法之一明确地在每一帧中编写代码:
声明每帧 运行 的内容脚本:
"content_scripts": [{ "matches": ["<all_urls>"], "js": ["content.js"], "run_at": "document_start", "all_frames": true, "match_about_blank": true }],
或在chrome.tabs.executeScript的选项中添加
allFrames: true, matchAboutBlank: true
。或使用核选项:chrome.debugger API to attach to the tab and send a CDP command like Page.addScriptToEvaluateOnNewDocument。缺点是它会在每个选项卡顶部显示警告通知。
在案例 1 和案例 2 中覆盖原型的代码 should be added in page context。另请注意,由于错误或固有限制,Chrome/Firefox 可能无法 运行 某些 iframe 中的内容脚本,例如 Firefox 中带有 CSP sandbox
的 iframe 或 Firefox 中带有 src="javascript:..."
的 iframe Chrome.