0

First things first :

  • I am developing an extension for google chrome
  • I have done sufficient research on how to build one and have got my manifest file and permissions all correct
  • I am using the browserAction model and have my popup.html page all setup which is displayed every time i click the browserAction icon
  • Just for debugging purposes, I have used a lot of window.alert popups in my code
  • The popup.html file includes a call to a javascript file "call_content_script.js" which then calls the "content_script.js" file.
  • The popup.html file also includes a link to another second_popup.js file

These are my codes :


popup.html

<!doctype html> 
<html> 
    <head>
    </head>

    <body>
        <h1>My Hello World Extension!</h1>
        <a href="second_popup.html">go to some other page</a>
        <script src="../javascript/call_content_script.js"></script>
        <!-- JAVASCRIPT FILES HAVE TO BE RUN FROM A SEPERATE 
              SCRIPT FILE. THIS IS A SECURITY FEATURE, ADDED
              IN MANIFEST VERSION 2.0
        -->
    </body>

</html>

second_popup.html

<!doctype html>
<html>
<body>
    <p>nothing to see here</p>
    <a href="popup.html">go back</a>
</body>
</html>

call_content_script.js

window.alert('call content script working');

chrome.tabs.query({"active":true},function(tabs) {
    window.alert(tabs[0].id);
    chrome.tabs.executeScript({file:"content_script.js"});
    //REQUIRES "permissions" : "activeTab"
});

window.alert('exiting call_content_script');

content_script.js

window.alert('content script working');

Now, I am facing two problems :

  1. every alert window pops up, except the one called in the content_script.js.
  2. After the I click the link from popup.html to second_popup.html, there is a popup for short time and then the popup window closes.

I dont understand why this is hapenning.


Thanks in advance

ironstein
  • 421
  • 5
  • 16
  • 1
    1. Try using `console.log('text')` instead of `alert` (maybe it's blocked) 2. Try adding `onbeforeunload` event handler in the second popup and set a breakpoint inside using devtools debugger – wOxxOm Sep 03 '15 at 05:13
  • 2
    dont use alerts. they will interfere with the popup when changing the focus. – Zig Mandel Sep 03 '15 at 13:13
  • @ZigMandel I am not able to use console.log in any case. Do you happen to know why ? – ironstein Sep 04 '15 at 00:07
  • yes you can. google how to view the popup console – Zig Mandel Sep 04 '15 at 00:23
  • @ZigMandel what I did is now I am using a background.js script instead of the popup, and I am listening for onClicked event of browserAction. I am using chrome.tabs.executeScript({file:"content_script.js"}) to call the content script file. The problem is when I use chrome.tabs.executeScript({code:"console.log("some_string")"}) in the content script, I get an error --> "tried to get executeScript of undefined", which means that the content script can not access the chrome object. Why is this hapenning ? – ironstein Sep 04 '15 at 12:32
  • that belongs to a new question. unrelated to original q. – Zig Mandel Sep 04 '15 at 12:33
  • @ZigMandel http://stackoverflow.com/questions/32398709/chrome-object-not-accessible-from-script-other-than-a-background-script – ironstein Sep 04 '15 at 12:59

0 Answers0