-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For headless code, use JS context instead of EEx interpolation
- Loading branch information
Showing
3 changed files
with
55 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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); | ||
await page.waitForNetworkIdle({ idleTime: 1000 }); | ||
|
||
const plausibleInstalled = await page.evaluate(() => { | ||
window.__plausible = true; | ||
if (typeof (window.plausible) === "function") { | ||
window.plausible('verification-agent-test', { | ||
callback: function(options) { | ||
window.plausibleCallbackResult = () => options && options.status ? options.status : 1; | ||
} | ||
}); | ||
return true; | ||
} else { | ||
window.plausibleCallbackResult = () => 0; | ||
return false; | ||
} | ||
}); | ||
|
||
await page.waitForFunction('window.plausibleCallbackResult', { timeout: 2000 }); | ||
const callbackStatus = await page.evaluate(() => { | ||
if (typeof (window.plausibleCallbackResult) === "function") { | ||
return window.plausibleCallbackResult(); | ||
} else { | ||
return 0; | ||
} | ||
}); | ||
|
||
return { | ||
data: { | ||
plausibleInstalled, callbackStatus | ||
}, | ||
type: "application/json" | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.