2024-05-23 16:00:50 +03:00
|
|
|
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);
|
|
|
|
|
2024-05-24 11:40:59 +03:00
|
|
|
try {
|
2024-06-18 06:58:56 +03:00
|
|
|
await page.waitForFunction('window.plausible', { timeout: 5000 });
|
2024-05-24 11:40:59 +03:00
|
|
|
await page.evaluate(() => {
|
|
|
|
window.__plausible = true;
|
2024-05-23 16:00:50 +03:00
|
|
|
window.plausible('verification-agent-test', {
|
|
|
|
callback: function(options) {
|
2024-05-24 11:40:59 +03:00
|
|
|
window.plausibleCallbackResult = () => options && options.status ? options.status : -1;
|
2024-05-23 16:00:50 +03:00
|
|
|
}
|
|
|
|
});
|
2024-05-24 11:40:59 +03:00
|
|
|
});
|
2024-05-23 16:00:50 +03:00
|
|
|
|
2024-05-24 11:40:59 +03:00
|
|
|
try {
|
2024-06-18 06:58:56 +03:00
|
|
|
await page.waitForFunction('window.plausibleCallbackResult', { timeout: 5000 });
|
2024-05-24 11:40:59 +03:00
|
|
|
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 } };
|
2024-05-23 16:00:50 +03:00
|
|
|
}
|
2024-05-24 11:40:59 +03:00
|
|
|
} catch ({ err, message }) {
|
|
|
|
return {
|
|
|
|
data: {
|
|
|
|
plausibleInstalled: false, callbackStatus: 0, error: message
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2024-05-23 16:00:50 +03:00
|
|
|
}
|
2024-05-24 11:40:59 +03:00
|
|
|
|