立即安装后Chrome扩展程序崩溃

时间:2015-11-30 04:02:25

标签: google-chrome-extension

我的应用程序执行我的chrome扩展的内联安装(假设它没有安装)。在用户安装了扩展程序后,我的应用程序会将其第一条消息发送到扩展程序。

factory.messageExtension = function (newPost) {

    var deferred = $q.defer();

    $window.postMessage({
        'cmd': 'create',
        'data': newPost
    }, "*");

    deferred.resolve();

    return deferred.promise;
};

错误Uncaught TypeError: Cannot read property 'name' of undefined316

的第@extensions::messaging:行引发

if (port.name != kNativeMessageChannel)...

完整的调用堆栈是:

sendMessageImpl @   extensions::messaging:316
(anonymous function)    @   extensions::runtime:115
target.(anonymous function) @   extensions::SafeBuiltins:19
(anonymous function)    @   extensions::binding:57
target.(anonymous function) @   extensions::SafeBuiltins:19
(anonymous function)    @   extensions::binding:385
(anonymous function)    @   inject.js:17

我一直调到383@extensions::binding,发现当retval等于Port = {}时,{ "manifest_version": 2, "name": "crypto - crypto", "short_name": "crypto", "version": "0.2", "homepage_url": "https://www.placeholder.com", "browser_action": { "default_icon": "icons/48x48.png" }, "icons": { "16" : "icons/16x16.png", "48" : "icons/48x48.png", "128" : "icons/128x128.png" }, "background": { "scripts": [ "js/mootools-core-1.3.1.js", "js/common.js", "js/background.js", "js/categories.js", "js/locations.js", "js/authentication.js" ] }, "externally_connectable": { "matches": ["*://localhost/*"] }, "permissions": [ "storage", "tabs", "<all_urls>", "*://*/*" ], "web_accessible_resources": [ "js/*" ], "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", "content_scripts": [{ "matches": [ "*://*/*" ], "js": [ "js/mootools-core-1.3.1.js", "js/mootools-more-1.4.0.1.js", "js/common.js", "js/autoposter.js", "js/inject.js" ], "run_at": "document_end", "all_frames": false }] } 未定义

正如我们在这里清楚的那样,如果已经安装了扩展名,则retval等于。 enter image description here

但是当扩展程序尚未安装并因此要求用户安装扩展程序时,它会向扩展程序发送消息,这是我们所看到的:

enter image description here

这是manifest.json

//this listens for messages from inject
chrome.runtime.onMessage.addListener(ext.handleInjectMessages);

//this watches the button in the chrome's chrome
chrome.browserAction.onClicked.addListener(ext.clickedIcon);

//this watches for the tab to close
chrome.tabs.onRemoved.addListener(ext.handleTabClose);

//this listens for request to check version of extension from external application
chrome.runtime.onMessageExternal.addListener(ext.checkVersion);


// Check whether new version is installed
chrome.runtime.onInstalled.addListener(function(details){
    if(details.reason == "install"){
        console.log("This is a first install!");
    }else if(details.reason == "update"){
        var thisVersion = chrome.runtime.getManifest().version;
        console.log("Updated from " + details.previousVersion + " to " + thisVersion + "!");
    }
});

这是background.js听众

{ read pid; read result; } < <(echo $$; echo mypass)

0 个答案:

没有答案
相关问题