0

I have this code below that until last week was working, but now when I will go execute again, this not works.

Based in this question and tested by me, using chrome.tabs.onUpdated.addListener event, works fine, but I have some strings in msgBox.js file, that cause errors relative to encoding (UTF-8/ANSI) and because this, all script inside of msgBox.js file is necessary execute using chrome.tabs.executeScript.

msgBox.js

function msg()
{

alert("hello!");

}

msg();

event.js

    chrome.webRequest.onCompleted.addListener(

    function onWindowLoad() {
    chrome.tabs.executeScript(null, {
    file: "msgBox.js"
    }, function() { 
    });
    }
    , 
    {
        urls: ["<all_urls>"],
        types: ["main_frame"]
    },
    ["responseHeaders"]

);

manifest.json

{
   "background": {

    //  "page": "popup.html"
      "scripts": ["event.js"]
   },

   "description": "Media Player for Flash",
   "manifest_version": 2,
   "name": "Media Player",  
   "icons": {
    "128" : "picture/flash128.png" ,
    "48" : "picture/flash48.png" 
},

"web_accessible_resources": [

   "event.js"
],

"content_scripts": [ 

{  

   "matches": ["<all_urls>", "*://*/*", "http://*/*", "https://*/*"],
   "js": ["event.js"],
   "run_at": "document_end",
   "all_frames": true
}

],

   "permissions": [ "tabs", "background", "activeTab", "<all_urls>", "webNavigation", "webRequest", "http://*/*", "https://*/*", "*://*/*" ],
   "version": "1.0"
}

What can is wrong?

Any help will welcome.

Community
  • 1
  • 1

1 Answers1

-1

According to https://developer.chrome.com/extensions/tabs#method-executeScript

null is not a valid option for object in "executeScript", Try using "string" in it's place. It worked for me at least when trying to reproduce and fix

Edit: although that does not explain why it worked before but stopped

goatcheese90
  • 9
  • 1
  • 2
  • Which version of Google Chrome you is using? –  May 29 '16 at 03:23
  • Version 50.0.2661.102 (64-bit) – goatcheese90 May 29 '16 at 03:27
  • Oops, just realized I hadn't updated yet, since I did no longer works for me either. Apologies. Before I updated, it was not working with "null" but did as soon as I changed to "string" so I igured that was it – goatcheese90 May 29 '16 at 03:30
  • OK, I think that Google Chrome haves blocked use of `chrome.tabs.executeScript` in recent versions of browser, like I was already thinking. –  May 29 '16 at 03:40
  • http://imgur.com/KDJs6Xp It looks like maybe it was chrome.webRequest that has been blocked or changed – goatcheese90 May 29 '16 at 03:53
  • If you test making: `chrome.webRequest.onCompleted.addListener( alert("Hi"); );` will work. –  May 29 '16 at 13:40
  • @Franciscocamilo: Your code works for me (Chrome 51.0.2704.63 m on Windows). Do you get any error messages in the console? The `null` tabId can be an issue under special circumstances, if no active tab of current window is available (eg. when running the code from the console). BTW, you mention `chrome.tabs.onUpdated.addListener` in your question, but it is not included anywhere in your code... – Petr Srníček May 29 '16 at 14:59
  • 1
    @Franciscocamilo. The error seems pretty self explanatory. Just convert the file to UTF-8 and this should be fixed. You can convert it in just about any text editor. Eg. in Notepad > File > Save As > select UTF-8 in the Encoding drop down. (I am not sure how the file could have worked with an incorrect encoding before though.) – Petr Srníček May 29 '16 at 15:59