Solution 1 :

No, you don’t need to deploy to the web store to get it to work.

You’re having a problem because you have attached much of the background script activity to the chrome.runtime.onInstalled listener – which only fires when the extension is installed or the manifest version changes. When you restarted the browser for the second time, your extension is installed already, the manifest version remains the same so that event won’t fire.

Solution 2 :

I figured out what to do:

as mentioned, the functions in the installed-listener are only called, when the script is actually installed (e.g. refresh) and not later when restarting the browser.

I found my Rookie mistake: I registered listeners asynchronously as is listed as a NOT TO DO in the Chrome documentation. In detail, this line should go out of the installed listener:


thanks for pointing me in the right direction!

Problem :

I started with chrome extensions three days ago and I like it quite a bit. I ran into a problem: I minimalized the script that reproduces my problem:

If I am on, I can click the icon and a popup will open that said ‘worked’, if it sent a message to the background script and received the message ‘worked’.

If I now restart the browser, I get a popup that extensions in developer mode could be harmful and whether I want to deactivate them. I dismiss this message and when I now click the extension it doesn’t work and I get the following error:

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

I figured out that the background script is NOT running (I get no alert from background.js or prints to the background.js console). I suppose the extension and therefore background.js was probably prevented from starting by chrome as it is an extension in developer mode. The only way to get the extension running again is to refresh the extension from chrome://extensions.

I tried it with persistent and non-persistent background script, but that didn’t change the behaviour.

Is my analysis correct and therefore the only solution to deploy the script on the webstore to make it run properly? Or is there another way to make the app in developer mode start when chrome starts?

Here is the minimal example:


    "name": "BackgroundScript Error",
    "version": "0.0.1",
    "manifest_version": 2,
    "description": "When starting Chrome, background doesn't start, but when refreshing, background starts",
    "page_action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
    "permissions": ["declarativeContent", "<all_urls>"],
    "background": {
        "scripts": ["background.js"],
        "persistent": false


chrome.runtime.onInstalled.addListener(function() {
    console.log('Background script is running');
    alert("Background is running");
    chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
        conditions: [new chrome.declarativeContent.PageStateMatcher({
            pageUrl: {hostEquals: ''},
        actions: [new chrome.declarativeContent.ShowPageAction()]

    console.log('setting up connection to popup');

chrome.runtime.onMessage.addListener(function(request, sender) {

function connected(p) {
    console.log("connected to "+p);
    p.postMessage({action: 'didSomething', result: 'worked' });

function disconnected(p) {
    console.log("disconnected from "+p);


var myPort

function onWindowLoad() {
    var message = document.getElementById('message');

    myPort = chrome.runtime.connect({name:"port-from-cs"});
    myPort.postMessage({request: "doSomething"});
    myPort.onMessage.addListener(function(m) {
        console.log("In popup script, received message from background script: ");
        message.innerHTML = m.result;

window.onload = onWindowLoad;


<!DOCTYPE html>
<html style=''>
        <script src='popup.js' ></script>

        <div id="message">Popup</div>




Comment posted by How to aim a bug in Chromium browser extension that there won’t be if installed locally in Dev mode


Comment posted by matanster

It’s hard for me to pin down a developer flow around this, as