0
votes

The content-script or in the background I get the title, but his pass or get-opens popup window with your script - it does not get the title of the page is obtained (necessary h1 of the page on which this expansion popup opens)?

UPD: In the popup-window, I want to convey title to the server, but in the same script, I can not get the standard script, also comes undefined localStorage, although on the whole page, I kept the title in localStorage another script (which content.js) .

Manifest is following:

{
    "manifest_version": 2,
    "version": "0.1",
    "name": "Title",
    "description": "Description",
    "content_scripts": [
        {
            "matches": [ "*://*/*" ],
            "css": ["ctyle.css"],
            "js": ["content.js"],
            "run_at": "document_end"
        }
    ],
    "background": {
    "scripts": ["background.js"]
  },
    "icons" : {
        "16" : "icon-16.png",
        "48" : "icon-48.png",
        "128" : "icon-128.png"
    },
    "permissions": [
        "tabs",
        "Need site/*",
        "storage"
  ],
    "browser_action": {
        "default_title": "Title",
        "default_icon" : "icon-32.png",
        "default_popup": "popup.html"
    }
}
1

1 Answers

0
votes

You can use document.querySelectorAll this method returns all elements in the document that matches a specified CSS selectors.

document.querySelectorAll("h1")

or

Use document.getElementsByTagName this method returns a collection of all elemets in the document with the specific tag name.

document.getElementsByTagName("h1")

Here's a SO ticket related on how to retrieve h1 heading element: How do I get all h1,h2,h3 etc elements in javascript?