私はちょうどMDN example chrome extensionを働かせようとしています。私はexample.com
をロードする際に、ここで私はChrome拡張機能がブロックされていませんwebRequest does not all working
- にそれを期待manifest.jsonをここ
{ "description": "Altering HTTP responses", "manifest_version": 2, "name": "http-response-filter", "version": "1.0", "homepage_url": "https://github.com/mdn/webextensions-examples/tree/master/http-response", "icons": { "48": "SA-48x48.png" }, "background": { "scripts": ["background.js"] } }
とはbackground.js
あるfunction listener(details) { console.log("******listen"); let filter = browser.webRequest.filterResponseData(details.requestId); let decoder = new TextDecoder("utf-8"); let encoder = new TextEncoder(); filter.ondata = event => { let str = decoder.decode(event.data, { stream: true }); // Just change any instance of Example in the HTTP response // to WebExtension Example. str = str.replace(/Example/g, "WebExtension Example"); filter.write(encoder.encode(str)); filter.disconnect(); }; return {}; } console.log("******"); browser.webRequest.onBeforeRequest.addListener( listener, { urls: ["https://example.com/*"], types: ["main_frame"] }, ["blocking"] );
はカップルのconsole.logsを出しています
- MDNの人々が述べたように "例"から "WebExtension Example"に変更する
しかし、それはまったく動作しません(私はChromeを使用しています。これを拡張機能として拡張機能として追加しました。以前は他のChrome拡張機能を使っていましたが、これは初めてのバックグラウンドスクリプトです)。
何かがこのバックグラウンドスクリプトの実行をブロックしている可能性はありますか?私はちょうど正しい方法でそれを設定していないのですか?私は正しい方向に、非常にありがとうポイントしてください。
クロームはそれが動作しませんので、応答本体の変更をサポートしていません。 – wOxxOm
私はそれが本当だとは思わない、私はMDNから直接得て、私はこのAPIを使用する他の拡張(例えばSmileAlways)を見た。私はここにセットアップがあると思います。 – swyx
私の投稿は実際にはあなたの質問に対する答えではなかったので削除しました。コメントは提案に適しています。 \t console.logは、スクリプトがロードされていれば何かをコンソールに表示するはずです。ちなみに、デバッグ時に拡張機能の背景ページを調べていますか? – maxpaj