Chrome script rich content content does not access the DOM page into which it is entered

I am trying to extract data from the page that the user is viewing and sends this data to the extension popup. I'm having problems retrieving information from the current page. After exploring the Google tutorials, I installed my manifest and content script as shown below. When I go to the test page with the range id = "comments", my variable from the nested content of the script always ends up as null. Does anyone know what I can lose? Thank!

manifest.json
=================
{
    "name": "Sample Extension",
    "version": "0.0.1",
    "description": "Sample extension",
    "icons": {"128": "icon.png"},
    "permissions": [
        "tabs", "<all_urls>"
    ],
    "browser_action": {
        "default_icon": "browseraction.png",
        "default_title": "Sample",
        "popup": "popup.html"
    },
    "content_scripts": [
        {
            "matches": ["http://*/*", "<all_urls>" ],
            "js": ["scripts/contentscript.js"]
        }
    ]
}

contentscript.js
===================
var comments = document.getElementById("comments");
alert( comments.innerText );
+5
source share
1 answer

Perhaps comments are loaded after your script is executed.

:

        "run_at" : "document_end",

, AJAX, setTimeout.

, .

+6

All Articles