0

I'm trying to perform a super simple task with extensions which is: on click, open popup, find data on page, populate popup fields and ajax that data over to an external script. However, I can't seem to get the script to populate my popup nor log anything in the console nor alert() me of anything, which is necessary so I know that I got the correct data. Here's what I'm running:

manifest.json

{
    "manifest_version": 2,
    "name": "Test ext",
    "description": "Test ext",
    "version": "0.2",
    "background": {
        "scripts": ["event.js", "jquery.min.js"],
        "persistent": false
    },
    "browser_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
    },
    "permissions": [
        "tabs", 
        "http://*/*", 
        "https://*/*"
    ]
}

popup.html

<html>
<head>
    <title>Auto Order</title>
</head>
<body>
    <span>Order id:<p id="orderid"></p></span>

</body>
</html>

event.js

    var orderid = $( "left post-rel" ).text();
    alert(orderid);
    console.log(orderid);

Again, I'm trying to make this as simple as possible. I assume once I understand how to populate popup.html fields I'll understand how to ajax that data offsite.

Predrag Beocanin
  • 1,402
  • 3
  • 18
  • 25

1 Answers1

1

Background scripts run in their own invisible, empty page page.

Looks like you're trying to make the background script manipulate both the visible tab (it can't, you need a content script) and the popup (you can't*, you need to add <script> to the popup itself).

Get a look at the Architecture Overview.

*: In principle you can with chrome.extension.getViews(), but it's usually not a good idea.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • Not really manipulate, just grab data off of it, so this means I have to make ` – Predrag Beocanin Dec 21 '14 at 21:00
  • 1
    Not enough even. You can't grab data off a regular tab in the `event.js`. You need a content script for that. Look at [this question](http://stackoverflow.com/q/27477641/934239), it can help. – Xan Dec 21 '14 at 21:03