1) ``` if (param1.responseType === "stream" || param1.fetch || param1.redirect) { // 只有fetch支持ReadableStream、redirect这些,直接使用fetch return this.CAT_fetch(param1, sender, resultParam); } ``` 不正确。 `GM_xmlhttpRequest` 用 fetch API 模拟 xmlhttpRequest 的条件是, `fetch:true`, `redirect`, `anonymous` 另外 `GM_xmlhttpRequest` 呼叫 `CAT_xxxx` 这个写法也不合适 2) `xmlhttpRequest`版 和 `fetch`版 的实作部份应该放在 pkg 工具库 而不是跟 GM_API 代码混在一起 ( dealXhrResponse 和 dealFetch 等相关代码) 实际应用时,`xmlhttpRequest`版 的 xmlhttprequest 由Offscreen 提供 3) stream, buffer, redirect, responseType 等部份要重写 4) 严格使用 xmlhttpRequest ,只有在 `fetch: true` 才使用 fetch版。重申 fetch 只是一个较好的做法,但 `GM_xmlhttpRequest` 本身所有options都可以用 最原始的 xmlhttpRequest 实现 (不包括TM增加的 `redirect` 和 `anonymous`) --- 由于MV3倾向fetch API 因此,实作部份,应把logic倒过来, fetch 预设true, 除非 onProgress 那些xhr限定的东西指定了 ---- ## 補充 ### stream 要 fetch. 因為xhr response 要等 readyState4 ### chrome 只能在同一頁面的service worker 傳 blob/arraybuffer, chrome mv2/mv3 的 messaging api 是 JSON serialization 而不是 firefox的 structured clone algorithm. * https://developer.chrome.com/blog/workers-arraybuffer?hl=en * https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Transferable_objects * https://developer.chrome.com/docs/extensions/develop/concepts/messaging?hl=en#serialization * https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities#data_cloning_algorithm ### 日後chrome 或會改成 structured clone algorithm * https://issues.chromium.org/issues/40321352 ### `@types/chrome` 說明有錯 * https://github.com/DefinitelyTyped/DefinitelyTyped/issues/73946
不正确。
GM_xmlhttpRequest用 fetch API 模拟 xmlhttpRequest 的条件是,fetch:true,redirect,anonymous另外
GM_xmlhttpRequest呼叫CAT_xxxx这个写法也不合适xmlhttpRequest版 和fetch版 的实作部份应该放在 pkg 工具库而不是跟 GM_API 代码混在一起
( dealXhrResponse 和 dealFetch 等相关代码)
实际应用时,
xmlhttpRequest版 的 xmlhttprequest 由Offscreen 提供stream, buffer, redirect, responseType 等部份要重写
严格使用 xmlhttpRequest ,只有在
fetch: true才使用 fetch版。重申 fetch 只是一个较好的做法,但GM_xmlhttpRequest本身所有options都可以用 最原始的 xmlhttpRequest 实现 (不包括TM增加的redirect和anonymous)由于MV3倾向fetch API
因此,实作部份,应把logic倒过来, fetch 预设true, 除非 onProgress 那些xhr限定的东西指定了
補充
stream 要 fetch. 因為xhr response 要等 readyState4
chrome 只能在同一頁面的service worker 傳 blob/arraybuffer, chrome mv2/mv3 的 messaging api 是 JSON serialization 而不是 firefox的 structured clone algorithm.
日後chrome 或會改成 structured clone algorithm
@types/chrome說明有錯chrome.declarativeNetRequest.RuleCondition.tabIdsDefinitelyTyped/DefinitelyTyped#73946