Я заметил, что вы можете использовать локальные переопределения в Devtools, позволяя вам редактировать контент JS сайта. Я попробовал все, что я мог придумать, чтобы воспроизвести это как расширение, но я либо получил CSP заблокирован (не могу переопределить это), либо в итоге оказался в каком-то условие гонки. PrettyPrint-Override ">(() => {
const targetPatterns = [
"foo"
];
const replacement = "bar";
const isBad = str => targetPatterns.some(tp => str.includes(tp));
const fixStr = str => (
targetPatterns.reduce((s, tp) => s.replaceAll(tp, replacement), str)
);
function patchExports(obj) {
if (!obj) return;
if (typeof obj === "string" && isBad(obj)) return fixStr(obj);
if (typeof obj === "object") {
for (const k of Object.keys(obj)) {
if (typeof obj[k] === "string" && isBad(obj[k])) {
obj[k] = fixStr(obj[k]);
}
}
}
}
function patchExecutedModules() {
if (typeof __webpack_require__ !== "function" ||
!__webpack_require__.c) return;
const cache = __webpack_require__.c;
let hit = 0;
for (const id in cache) {
if (patchExports(cache[id].exports)) hit++;
}
console.log(`[patcher] scrubbed ${hit} executed module(s)`);
}
function scanChunk(chunk) {
const modules = chunk[1] || {};
for (const id in modules) {
const factory = modules[id];
if (typeof factory !== "function") continue;
const src = factory.toString();
if (!isBad(src)) continue;
const orig = factory;
modules[id] = function (module, exports, require) {
orig(module, exports, require);
patchExports(exports);
};
console.log(`[patcher] wrapped module ${id}`);
}
}
function hookArray(arr, name) {
if (arr.__patched) return;
arr.__patched = true;
const origPush = arr.push.bind(arr);
arr.push = function (chunk) { scanChunk(chunk); return origPush(chunk); };
arr.forEach(scanChunk);
console.log(`[patcher] hooked ${name} (had ${arr.length} chunk(s))`);
}
function tryHook() {
const nativePush = Array.prototype.push;
for (const k of Object.keys(window)) {
const v = window[k];
if (Array.isArray(v) && typeof v.push === "function" && v.push !== nativePush) {
hookArray(v, k);
return true;
}
}
return false;
}
patchExecutedModules();
(function wait() {
if (!tryHook()) setTimeout(wait, 25);
})();
})();
Подробнее здесь: https://stackoverflow.com/questions/796 ... ension-mv3
Локальный переопределение эквивалент как расширение хрома (MV3) ⇐ Javascript
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение