analytics/priv/verification/verify_plausible_installed.js
hq1 1c820ba2af
Verification tweaks (#4234)
* Prioritize CSP over GTM error in case both detected

* Outline better message for persistent headless timeout

* Bump headless waiting times slightly

* Add generic type of error

For known cases, that we rather not reveal much
details about.

* Add the malformed script tag case
2024-06-18 05:58:56 +02:00

37 lines
1.0 KiB
JavaScript

export default async function({ page, context }) {
if (context.debug) {
page.on('console', (msg) => console[msg.type()]('PAGE LOG:', msg.text()));
}
await page.setUserAgent(context.userAgent);
await page.goto(context.url);
try {
await page.waitForFunction('window.plausible', { timeout: 5000 });
await page.evaluate(() => {
window.__plausible = true;
window.plausible('verification-agent-test', {
callback: function(options) {
window.plausibleCallbackResult = () => options && options.status ? options.status : -1;
}
});
});
try {
await page.waitForFunction('window.plausibleCallbackResult', { timeout: 5000 });
const status = await page.evaluate(() => { return window.plausibleCallbackResult() });
return { data: { plausibleInstalled: true, callbackStatus: status } };
} catch ({ err, message }) {
return { data: { plausibleInstalled: true, callbackStatus: 0, error: message } };
}
} catch ({ err, message }) {
return {
data: {
plausibleInstalled: false, callbackStatus: 0, error: message
}
};
}
}