-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: user defined user agent (#115)
* Feat: manually define user agent * WIP: Add options at page level * Page.setUserAgent * fmt * Example * Fix failing tests * fmt (again) * Lint * Small review tweaks
- Loading branch information
1 parent
142baec
commit 0d225de
Showing
3 changed files
with
57 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { launch } from "../mod.ts"; | ||
|
||
const browser = await launch(); | ||
|
||
const page = await browser.newPage("https://whatsmybrowser.org"); | ||
|
||
const getUserAgent = async () => { | ||
const uaElement = await page.$(".user-agent"); | ||
|
||
const ua = await uaElement?.innerText() || ""; | ||
|
||
console.log(ua); | ||
|
||
return ua; | ||
}; | ||
|
||
const userAgent = await getUserAgent(); | ||
|
||
// get current version of Chrome | ||
const version = userAgent?.split("Chrome/")?.at(1)?.split(".").at(0) || ""; | ||
|
||
// NOTE: this is *just* the major version, and may produce version | ||
// numbers that don't actually exist... but this is just for | ||
// demonstration, so that's fine | ||
const nextVersion = String(Number(version) - 1); | ||
|
||
await page.setUserAgent(userAgent?.replace(version, nextVersion)); | ||
|
||
await page.reload(); | ||
|
||
await getUserAgent(); | ||
|
||
await browser.close(); |
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