'Uncaught (in promise) ReferenceError: window is not defined in google chrome extension

it the fingerpints did not support google chrome extension? When I get visit id like this:

const DeviceHandler = {
    getDeviceId: async (): Promise<string> => {
        return new Promise((resolve, reject) => {
            const fpPromise = require('@fingerprintjs/fingerprintjs').load();
            fpPromise
                .then((fp: { get: () => any; }) => fp.get())
                .then(async (result: { visitorId: any; }) => {
                    // This is the visitor identifier:
                    const deviceId = result.visitorId;
                    resolve(deviceId);
                });
        });
    }
};

export default DeviceHandler;

shows error in the background.js:

Uncaught (in promise) ReferenceError: window is not defined

this is the function that throws error in fingerprints "@fingerprintjs/fingerprintjs": "^3.3.2",:

/**
 * Sends an unpersonalized AJAX request to collect installation statistics
 */
function monitor() {
    // The FingerprintJS CDN (https://github.com/fingerprintjs/cdn) replaces `window.__fpjs_d_m` with `true`
    if (window.__fpjs_d_m || Math.random() >= 0.01) {
        return;
    }
    try {
        var request = new XMLHttpRequest();
        request.open('get', "https://openfpcdn.io/fingerprintjs/v" + version + "/npm-monitoring", true);
        request.send();
    }
    catch (error) {
        // console.error is ok here because it's an unexpected error handler
        // eslint-disable-next-line no-console
        console.error(error);
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source