Is chrome.runtime.onInstalled.addListener really deprecated?

2,031 views
Skip to first unread message

Peter Kellner

unread,
May 9, 2019, 7:20:10 PM5/9/19
to Chromium Extensions
I'm following the example in the chrome dev getting started: https://developer.chrome.com/extensions/getstarted

and for some reason, my IDE (webstorm) is showing that addListener is deprecated. I assume eslint must be figuring that out.

Is that true? If so, what doc would show it and what do I replace it with?


chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({color: '#3aa757'}, function() {
console.log("The color is green.");
});
});

PhistucK

unread,
May 10, 2019, 3:26:24 AM5/10/19
to Peter Kellner, Chromium Extensions
When IDEs show a deprecation message, there is usually some guidance for alternatives, maybe the message can be expanded somehow to show that guidance?

Generally, the reference page in the documentation will show it -
In this case, it does not, so WebStorm might be showing this according to MDN (also not deprecated there) or their internal data/understanding (no reference here).

Not sure why it shows it as deprecated.

PhistucK


--
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 https://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/e2c3c9b6-3035-4d79-8a1d-f9216a1fca3f%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

wOxxOm

unread,
May 10, 2019, 10:11:18 AM5/10/19
to Chromium Extensions
Explanation:

Your IDE doesn't know about chrome namespace so it thinks you're using the ancient DOM method addListener, which is indeed deprecated.

Solution:

Install DefinitelyTyped bindings for chrome API:

PhistucK

unread,
May 10, 2019, 11:18:34 AM5/10/19
to wOxxOm, Chromium Extensions
DOM did not have addListener at any point, that I know of, but CSSOM did indeed have it (and it is still supported for backward compatibility) -
window.matchMedia('(max-width: 600px)').addListener(...)
(The addEventListener is supported by now)
So I guess wOxxOm meant that and WebStorm is just inferring the type wrongly (intentionally or not).

PhistucK


--
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 https://groups.google.com/a/chromium.org/group/chromium-extensions/.
Reply all
Reply to author
Forward
0 new messages