クロム拡張を作成しようとしています。この分野での最小限の経験私はInsert code into the page context using a content scriptの後に、最初のメソッドを使ってjsコードをページに挿入しました。クロム拡張のjavascriptアラートを無効にする
私はオーバーレイの機能を破壊しているアラートに大いに依存している他の人のコードよりもjsフレームワークを構築しようとしています。ちょっと沈黙させたいだけですメッセージをconsole.logに入れますが、私はこの段階で何を得ることができます。だから私は最終的なjsファイル(nogo.js)を注入するためにJavaScript: Overriding alert()を設定しようとしました。
nogo.jsが注入されますが、アラートを抑制する効果はないようです。それは、他のhtmlファイル自体が、注入が遅すぎたり、順不同で起こっている別のjsファイルによって開始されている可能性がありますか?
manifest.jsonを
"content_scripts": [
{
"matches": ["*://URL/*"],
"js": ["myscript.js"],
"run_at": "document_end",
"all_frames": true
},
{
"matches": ["*://URL/*"],
"js": ["noalerts.js"],
"run_at": "document_start",
"all_frames": true
}
],
"web_accessible_resources": ["script.js","nogo.js"]
}
myscript.js
var s = document.createElement('script');
// TODO: add "script.js" to web_accessible_resources in manifest.json
s.src = chrome.extension.getURL('script.js');
s.onload = function() {
this.remove();
};
(document.head || document.documentElement).appendChild(s);
noalerts.js
var n = document.createElement('script');
// TODO: add "script.js" to web_accessible_resources in manifest.json
n.src = chrome.extension.getURL('nogo.js');
n.onload = function() {
this.remove();
};
(document.head || document.documentElement).appendChild(n);
nogo.js
window.alert = null;
チップのおかげで、私はnogo.jsを注入することができましたが、残念ながらコードは警告ウィンドウを妨げていません。 – CursingLoudlyintheOffice
ここ:https://stackoverflow.com/q/12095924/632951 – Pacerier