1

I am trying to append a number to the beginning of each search result on google.com but my chrome extension is failing to do so. The css injection is working correctly but the js is not. I found that .S3Uucc is a common class name for the anchor tag on each result.

manifest.json:

{
    "manifest_version": 2,

    "name": "number",
    "version": "0.1.0",
    "description": "numbering",

    "browser_action": {
        "default_icon": "icon.png"
    },
    "background": {
        "scripts": ["jquery-3.4.1.js","number.js"]
    },

    "permissions": ["tabs", "<all_urls>", "file:///*"]

  }

number.js:


chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    chrome.tabs.insertCSS({file:"number.css"});
    $(document).ready(function(){
        var a = $(".S3Uucc").textContent;
        $(".S3Uucc").textContent="10: "+a;
    });
});
  • 1
    Does this answer your question? [How to access the webpage DOM rather than the extension page DOM?](https://stackoverflow.com/questions/4532236/how-to-access-the-webpage-dom-rather-than-the-extension-page-dom) – wOxxOm Nov 23 '19 at 09:13
  • 1
    The background script runs in a separate hidden background page which is not the web page, it's totally unrelated. You need a content script, see the linked topic. – wOxxOm Nov 23 '19 at 09:13
  • I am using this code now and it still isn't working (ps. i changed my manifest.json to match content_script that you suggested). https://pastebin.com/rtPqvtHC – Pratham Thukral Nov 23 '19 at 10:06
  • I believe I fixed the issue using jquery and a little more tinkering. Thank you for your help. – Pratham Thukral Nov 23 '19 at 10:48

0 Answers0