Chrome Extension : content script on facebook

前端 未结 1 1606
别跟我提以往
别跟我提以往 2020-12-17 05:42

I am creating a chrome extension for facebook. I need to execute the same content script on every page. It works well during the first load but it doesn\'t work when I go to

相关标签:
1条回答
  • 2020-12-17 06:35

    I personally solved this by using Chrome's webRequest API. You'll want to add a listener that tracks AJAX-generated HTTP calls. Here's essentially the code I used:

    chrome.webRequest.onCompleted.addListener(function(details) {
        var url = document.createElement('a');
        url.href = details.url;
        if (url.search && url.search.indexOf('ajaxpipe=1') !== -1) {
            console.log('New page via AJAX.');
            chrome.tabs.executeScript({'file' : 'test.js'});
        }
    }, {urls : ["*://*.facebook.com/*"]});
    
    0 讨论(0)
提交回复
热议问题