0

ユーザーがアクセスしているWebページの読み込みが完了次第、クローム拡張機能を実行することはできません。javascript - ページが読み込まれるとすぐにクロム拡張機能を実行する

クリックすると拡張機能はうまく動作しますが、ページの読み込み時に自動的に実行します。

これを行う方法はありますか?

は、ここに私のマニフェスト

{ 
    "manifest_version": 2, 

    "name": "Simple Text Highlighter", 
    "description": "This plugin notify of the word 'Simple' in the current page", 
    "version": "1.0", 

    "browser_action": { 
     "default_icon": "icon.png", 
     "default_popup": "popup.html" 
    }, 

    "content_scripts": [{ 
     "matches": ["http://*/*", "https://*/*"], 
     "js": ["jquery.min.js", "highlightSimple.js"], 
     "css": ["highlight.css"], 
     "run_at": "document_end" 
    }], 

    "permissions": [ 
     "tabs", 
     "activeTab", 
     "notifications", 
     "http://*/", 
     "https://*/" 
    ] 

} 

であり、ここで事前にはJavaScript

(function() { 
    chrome.tabs.executeScript(null, { 
     file: 'highlight.css' 
    }, function() { 
     chrome.tabs.executeScript(null, { 
      file: 'jquery.min.js' 
     }, function() { 
      chrome.tabs.executeScript(null, { 
       file: 'replace.js' 
      }); 
     }); 
    }) 
})(); 

おかげです。

答えて

0

run_atフィールドdocument_endを設定しました。これは、ページが読み込まれるとすぐにスクリプトが挿入されることを意味します。

ファイルは、DOMが完了した直後に、イメージやフレームなどのサブリソースが読み込まれる前に挿入されます。

chrome.tabs.executeScriptは、拡張コンテキストでのみ呼び出すことができますが、コンテンツスクリプトでは許可されていません。

関連する問題