Debug chrome.runtime.onInstalled

82 views
Skip to first unread message

Browser Extenstion

unread,
Jan 16, 2021, 8:27:52 AMJan 16
to Chromium Extensions

How can I check the behavior of upnpacked extension on chrome.runtime.onInstalled --> details.reason == 'update' ?

In another words I want mannualy to check the update of the extension during the development (before upload new version to the store).

wOxxOm

unread,
Jan 16, 2021, 9:07:03 AMJan 16
to Chromium Extensions, Browser Extenstion
Assuming the extension is installed in unpacked mode you can simply click the reload icon in the extension's card in chrome://extensions page.

Browser Extenstion

unread,
Jan 16, 2021, 10:18:55 AMJan 16
to Chromium Extensions, wOxxOm, Browser Extenstion
I'm not sure that it's the same behavior.
The reload button reload extension itself, it means the listener will be created after the code running.
When the extension updates in "real mode" the listener already exists.

Deliaz

unread,
Jan 16, 2021, 5:40:21 PMJan 16
to Chromium Extensions, Browser Extenstion
When the extensions updates in "real mode" the browser does almost the same click to the reload button. 
It sounds like you want to get info about the update is available for installation before installing it, right? 
Unfortunately that is not what `chrome.runtime.onInstalled` for. 

Browser Extenstion

unread,
Jan 17, 2021, 1:05:22 AMJan 17
to Chromium Extensions, d3l...@gmail.com, Browser Extenstion
No, I want to check the sequence of function calling.
Let's say the update event was fired while the extension is running.
So let's analyze it in simple code. What is the sequence of console.log()?

function start () {
    chrome.runtime.onInstalled.addListener(cb);
    console.log('start')
}
function cb(detalis) {
    // update happened
    if (details.reason == 'update')
        console.log('update')
}
start();

wOxxOm

unread,
Jan 17, 2021, 1:44:26 AMJan 17
to Chromium Extensions, Browser Extenstion, d3l...@gmail.com
onInstalled is not fired to the old extension, it's fired to the new extension after it was updated/installed so you can click the reload button as I suggested. 

Jackie Han

unread,
Jan 17, 2021, 2:52:55 AMJan 17
to wOxxOm, Chromium Extensions, Browser Extenstion, d3l...@gmail.com
This is the only document for onInstalled method. No other official document.

I have not studied the source code of chromium. As a developer, if the execution order is very important to you. From the point of view that the execution order is unknown (agnostic), there is a general programming skill - Setting and Checking your condition.

For example to your example,

var condition1 = false;
function start () {
    chrome.runtime.onInstalled.addListener(cb);
    condition1 = true;

}
function cb(detalis) {
    // update happened
    if (details.reason == 'update') {
        if(condition1) {
            // do something
        } else {
            // do others
        }
    }
}
start();

Best

--
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 view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/60bc0415-40b6-4c16-a21a-8daede255692n%40chromium.org.


--
韩国恺(Jackie)

Browser Extenstion

unread,
Jan 17, 2021, 6:08:46 AMJan 17
to Chromium Extensions, wOxxOm, Browser Extenstion, d3l...@gmail.com

You are absolutely right.

In that case, I'll change my question a bit.
How to find out that the update has NOT happened (chrome.runtime.onInstalled.addListener was not fired at all)?

In another words how to return any value if the extension has NOT been updated?

Kos

unread,
Jan 17, 2021, 6:54:52 AMJan 17
to Chromium Extensions, Browser Extenstion, wOxxOm, d3l...@gmail.com
>  In another words how to return any value if the extension has NOT been updated? 

It is as easy as checking if version changed:

if (chrome.runtime.getManifest().version === OLD_VERSION)
{
  // not updated, do your thing

Browser Extenstion

unread,
Jan 17, 2021, 7:43:52 AMJan 17
to Chromium Extensions, Kos, Browser Extenstion, wOxxOm, d3l...@gmail.com
The problem is more complicated.
chrome.runtime.getManifest().version shows you the current version, correct. But, it is not shows that extension was updated right now or not.
After extension updated this value will be the new version ever.

I'm asking about if this "iteration" (current run).
I want to change some values only if the extension updated rigth now, and not every run when chrome.runtime.getManifest().version === NEW_VERSION.

The problem is that chrome.runtime.onInstalled.addListener fires after the rest of the code has worked. I can wait until the listener return the value with Promise, but it works only if the update occured. If not the promise does not return nothing and the code stop running.

wOxxOm

unread,
Jan 17, 2021, 7:55:01 AMJan 17
to Chromium Extensions, Browser Extenstion, Kos, wOxxOm, d3l...@gmail.com
You'll have to postpone main execution to wait and see if the event fired or not, for example:

let installedNow;
chrome.runtime.onInstalled.addListener(() => {
  installedNow = true;
});
setTimeout(() => {
  if (!installed) {
    // do something
  }
});

This example uses the default timeout 0 (zero) but maybe you'll need to increase it.

Browser Extenstion

unread,
Jan 17, 2021, 2:18:50 PMJan 17
to Chromium Extensions, wOxxOm, Browser Extenstion, Kos, d3l...@gmail.com
Thanks everyone for the answers.
I found another way to check the update state using chrome.storage API.

Jackie Han

unread,
Jan 17, 2021, 2:38:00 PMJan 17
to Browser Extenstion, Chromium Extensions, wOxxOm, Kos, d3l...@gmail.com
Congrat!
Perhaps if you described your problem in more detail, we wouldn’t have to dwell on the execution order.

--
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.
Reply all
Reply to author
Forward
0 new messages