0

I want to use the function document.write in order to write something in the popup.html of a chrome.extension and I cant get it working. Have been crawling google for hours but still stuck.

popup.html

<!DOCTYPE html>
<html>
<head><meta charset="utf-8">
</head>
<body>
<div id ="master">
</div>
</body></html>

manifest.json

{
"manifest_version": 2,
"name": "Example",
"description": "Description",
"version": "1.0",
"browser_action": 
{
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "myweb.com"
},
"background": 
{
"scripts": [ "background.js" ],
"persistent": true
},
"permissions": [
"activeTab",
"alarms",
"storage",
"notifications",
"tabs"
]
}

here the code that causes problem in background.js:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
document.master.write( '<iframe src="http://www.xxxx.com/someaction" ' +
    'style="padding:0px; overflow:hidden;" '+
    'width="400px" height="350px"></iframe>' );
...///...

Error triggered:

Error in event handler for tabs.onUpdated: TypeError: Cannot read property 'write' of undefined

Thanks for your help !

  • 2
    Why are you even trying to do it from the background page? Actually, the question contradicts itself and doesn't provide a complete picture of what you're trying to achieve. The popup can update itself when it's open, you don't need the background page for that. It's a separate page. – wOxxOm Dec 04 '17 at 13:19
  • https://stackoverflow.com/questions/8858980/document-write-in-chrome-extension – alessandrio Dec 04 '17 at 13:40
  • ok, so you mean, when I open the popup, it has to launch the document.write script, located in another file ? – Erwan Conan Dec 04 '17 at 13:44
  • document.write can be used only while the page is loading or after you reset it with `document.open()`. Anyway, it's still not clear what you are trying to achieve. – wOxxOm Dec 04 '17 at 17:40
  • Ok it's a kind of Alexa.com tracker. On specific events it logs and adds data about pages visited into a database. I wanted to have informations from this database loaded into the popup.html once it pops up. – Erwan Conan Dec 04 '17 at 21:21
  • The thing is I dont know how to handle multiple JS files. Actually I am working on a single background.js file but I would like to know, how do I make the link between my background.js and my other JS file located on the server ?? – Erwan Conan Dec 04 '17 at 21:28

0 Answers0