I am in the process of developing a browser extension that would work seamlessly on Edge, Chrome, and Firefox by utilizing Typescript.
After coming across an article discussing interoperable browser extensions, I stumbled upon a code snippet:
window.browser = (function () {
return window.msBrowser ||
window.browser ||
window.chrome;
})();
This inspired me to consider creating a Browser class and setting a property based on the user's browser. Here's a draft of what I have in mind:
export class Browser {
constructor() {}
public _browser: object = null;
get browser() : object {
if (typeof window.chrome !== 'undefined') {
this._browser = window.chrome;
}
if (typeof window.browser !== 'undefined') {
this._browser = window.browser;
}
return this._browser;
}
}
While I successfully integrated @types/chrome for Chrome definition to prevent exceptions, I ran into a roadblock with finding type definitions for the browser
and msBrowser
objects in TypeScript. Are there any solutions or suggestions to handle this without encountering errors?
Thus, my query is whether there are any suitable type definitions available to support the browser
or msBrowser
objects?