How can I solve error: “Unchecked runtime.lastError while running tabs.executeScript:” for Ripple emulator Chrome Extension Target?

閲覧: 4,875 回
最初の未読メッセージにスキップ

Lesley. S. Munyuki

未読、
2014/10/22 18:22:182014/10/22
To: chromium-...@chromium.org

Hello, I have managed to build Ripple Emulator open source found here:

https://github.com/apache/incubator-ripple,

I built it using (Jake build) as the instructions say. (Jake build) also creates The Chrome Extension Target that allows me to test my web apps via a chrome extension of my built, as documented here:

https://github.com/apache/incubator-ripple/blob/master/doc/chrome_extension.md

I successfully loaded the unpacked extension onto chrome but when I enable it, nothing happens, though the page reloads the extension does not work, instead I get 2 these errors:

  1. Uncaught ReferenceError: webkitNotifications is not defined its specifically highlighting the following line as the one in error

               webkitNotifications.createHTMLNotification('/views/update.html').show();

2. Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL its specifically highlighting the following line as the one in error
chrome.tabs.executeScript(tabId, {

FULL background.js contents

if (!window.tinyHippos) {
window
.tinyHippos = {};
}

tinyHippos
.Background = (function () {
var _wasJustInstalled = false,
    _self
;

function isLocalRequest(uri) {
   
return !!uri.match(/^https?:\/\/(127\.0\.0\.1|localhost)|^file:\/\//);
}

function initialize() {
   
// check version info for showing welcome/update views
   
var version = window.localStorage["ripple-version"],
        xhr
= new window.XMLHttpRequest(),
        userAgent
,
        requestUri
= chrome.extension.getURL("manifest.json");

    _self
.bindContextMenu();

    xhr
.onreadystatechange = function () {
       
if (xhr.readyState === 4) {
           
var manifest = JSON.parse(xhr.responseText),
                currentVersion
= manifest.version;

           
if (!version) {
                _wasJustInstalled
= true;
           
}

           
if (version !== currentVersion) {
                webkitNotifications
.createHTMLNotification('/views/update.html').show();
           
}

            window
.localStorage["ripple-version"] = currentVersion;
       
}
   
};

    xhr
.open("GET", requestUri, true);

    xhr
.send();

    chrome
.extension.onRequest.addListener(function (request, sender, sendResponse) {
       
switch (request.action) {
       
case "isEnabled":
            console
.log("isEnabled? ==> " + request.tabURL);
            sendResponse
({"enabled": tinyHippos.Background.isEnabled(request.tabURL)});
           
break;
       
case "enable":
            console
.log("enabling ==> " + request.tabURL);
            tinyHippos
.Background.enable();
            sendResponse
();
           
break;
       
case "version":
            sendResponse
({"version": version});
           
break;
       
case "xhr":
           
var xhr = new XMLHttpRequest(),
                postData
= new FormData(),
                data
= JSON.parse(request.data);

            console
.log("xhr ==> " + data.url);

            $
.ajax({
                type
: data.method,
                url
: data.url,
                async
: true,
                data
: data.data,
                success
: function (data, status) {
                    sendResponse
({
                        code
: 200,
                        data
: data
                   
});
               
},
                error
: function (xhr, status, errorMessage) {
                    sendResponse
({
                        code
: xhr.status,
                        data
: status
                   
});
               
}
           
});
           
break;
       
case "userAgent":
       
case "lag":
       
case "network":
           
// methods to be implemented at a later date
           
break;
       
default:
           
throw {name: "MethodNotImplemented", message: "Requested action is not supported!"};
           
break;
       
};
   
});

    chrome
.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
       
if (tinyHippos.Background.isEnabled(tab.url)) {
            chrome
.tabs.executeScript(tabId, {
                code
: "rippleExtensionId = '" + chrome.extension.getURL('') + "';",
                allFrames
: false
           
}, function () {
                chrome
.tabs.executeScript(tabId, {
                    file
: "bootstrap.js",
                    allFrames
: false
               
});
           
});
       
}
   
});
}

function _getEnabledURIs() {
   
var parsed = localStorage["tinyhippos-enabled-uri"];
   
return parsed ? JSON.parse(parsed) : {};
}

function _persistEnabled(url) {
   
var jsonObject = _getEnabledURIs();
    jsonObject
[url.replace(/.[^\/]*$/, "")] = "widget";
    localStorage
["tinyhippos-enabled-uri"] = JSON.stringify(jsonObject);
}

_self
= {
    metaData
: function () {
       
return {
            justInstalled
: _wasJustInstalled,
            version
: window.localStorage["ripple-version"]
       
};
   
},

    bindContextMenu
: function () {
       
var id = chrome.contextMenus.create({
           
"type": "normal",
           
"title": "Emulator"
       
});

       
// TODO: hack for now (since opened tab is assumed to be page context was called from
       
// eventually will be able to pass in data.pageUrl to enable/disable when persistence     refactor is done
        chrome
.contextMenus.create({
           
"type": "normal",
           
"title": "Enable",
           
"contexts": ["page"],
           
"parentId": id,
           
"onclick": function (data) {
                    _self
.enable();
               
}
       
});

        chrome
.contextMenus.create({
           
"type": "normal",
           
"title": "Disable",
           
"contexts": ["page"],
           
"parentId": id,
           
"onclick": function (data) {
                    _self
.disable();
               
}
       
});
   
},

    enable
: function () {
        chrome
.tabs.getSelected(null, function (tab) {
            console
.log("enable ==> " + tab.url);
            _persistEnabled
(tab.url);
            chrome
.tabs.sendRequest(tab.id, {"action": "enable", "mode": "widget", "tabURL": tab.url });
       
});
   
},

    disable
: function () {
        chrome
.tabs.getSelected(null, function (tab) {
            console
.log("disable ==> " + tab.url);

           
var jsonObject = _getEnabledURIs(),
                url
= tab.url;

           
while (url && url.length > 0) {
                url
= url.replace(/.[^\/]*$/, "");
               
if (jsonObject[url]) {
                   
delete jsonObject[url];
                   
break;
               
}
           
}

            localStorage
["tinyhippos-enabled-uri"] = JSON.stringify(jsonObject);

            chrome
.tabs.sendRequest(tab.id, {"action": "disable", "tabURL": tab.url });
       
});
   
},

    isEnabled
: function (url, enabledURIs) {
       
if (url.match(/enableripple=/i)) {
            _persistEnabled
(url);
           
return true;
       
}

           
// HACK: I'm sure there's a WAY better way to do this regex
       
if ((url.match(/^file:\/\/\//) && url.match(/\/+$/)) || url.match(/(.*?)\.        (jpg|jpeg|png|gif|css|js)$/)) {
           
return false;
       
}

        enabledURIs
= enabledURIs || _getEnabledURIs();

       
if (url.length === 0) {
           
return false;
       
}
       
else if (enabledURIs[url]) {
           
return true;
       
}

         
return tinyHippos.Background.isEnabled(url.replace(/.[^\/]*$/, ""), enabledURIs);
   
}
   
};

    initialize
();

   
return _self;
}());

Full manifest.json File


{
"version": "1",
"manifest_version": 2,
"name": "Ripple Emulator (Beta)",
"background": {
   
"page": "views/background.html"
},
"web_accessible_resources": [],
"icons":{
   
"16":"images/Icon_16x16.png",
   
"128":"images/Icon_128x128.png",
   
"48":"images/Icon_48x48.png"
},
"browser_action":{
   
"default_popup":"views/popup.html",
   
"default_icon":"images/Icon_48x48.png",
   
"default_title":"Ripple"
},
"content_scripts":[{
   
"run_at": "document_start",
   
"js": ["controllers/Insertion.js"],
   
"matches": ["http://*/*","https://*/*","file://*"]
},
{
   
"run_at": "document_start",
   
"js": ["controllers/frame.js"],
   
"matches": ["http://*/*","https://*/*","file://*"],
   
"all_frames": true
}],
"permissions": ["tabs", "unlimitedStorage", "notifications", "contextMenus", "webRequest", "<all_urls>"],
"description": "A browser based html5 mobile application development and testing tool"
}

what can i do to solve this problem, i have looked at similar questions here but i cannot resolve it.

Any help would be appreciated. Thanks in advance.


Mats David Vincent Patzke

未読、
2014/10/23 8:31:382014/10/23
To: Lesley. S. Munyuki、chromium-...@chromium.org
Hey,

to the first error: The  webKitNotifications.createHTMLNotification()  is deprecated and can not be used any more. For more information look here https://developer.chrome.com/extensions/desktop_notifications.

to the second error: Normally you can ignore this kind of error. This error message appears when you open a chrome-url without a check before chrome.tabs.executeScript() for chrome-urls. But it does not harm the extensions per se.

Cheers 
David Patzke

 

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/2bb6b411-ce78-4e27-b25a-ec399b77dc79%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Lesley. S. Munyuki

未読、
2014/10/23 9:50:282014/10/23
To: chromium-...@chromium.org、lsmu...@gmail.com
Thank you for your reply David

That eliminates those two issues, but that means the extension is not working due to another problem i'm unaware of.. oh man.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
全員に返信
投稿者に返信
転送
新着メール 0 件