forked from erik/strava-heatmap-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
60 additions
and
86 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,54 @@ | ||
#!/usr/bin/env node | ||
// | ||
// Log a user into Strava and write the cookies to stdout for later use. | ||
import puppeteer from "puppeteer"; | ||
|
||
const STRAVA_EMAIL = process.env.STRAVA_EMAIL; | ||
const STRAVA_PASSWORD = process.env.STRAVA_PASSWORD; | ||
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"; | ||
const REQUIRED_COOKIE_NAMES = [ | ||
"CloudFront-Policy", | ||
"CloudFront-Key-Pair-Id", | ||
"CloudFront-Signature", | ||
"_strava4_session", | ||
]; | ||
|
||
console.log("Launching browser..."); | ||
let browser = await puppeteer.launch({ | ||
headless: true, | ||
devtools: false, | ||
timeout: 0, | ||
args: ["--no-sandbox", "--disable-setuid-sandbox", "--disable-blink-features=AutomationControlled",], | ||
}); | ||
|
||
console.log("Opening new page..."); | ||
const page = await browser.newPage(); | ||
|
||
await page.setUserAgent(USER_AGENT); | ||
await page.setViewport({width: 1280, height: 800}); | ||
|
||
console.log("Opening strava login...") | ||
await page.goto("https://www.strava.com/login", {waitUntil: "networkidle2"}); | ||
|
||
console.log("Logging in with email and password...") | ||
await page.type("#desktop-email", STRAVA_EMAIL); | ||
await page.type("#desktop-current-password", STRAVA_PASSWORD); | ||
|
||
let submitLoginElement = await page.waitForSelector('button[type="submit"]:not([disabled])', {visible: true}); | ||
await submitLoginElement.click() | ||
await page.waitForNavigation({waitUntil: "networkidle2"}); | ||
|
||
console.log("Loading global heatmap..."); | ||
await page.goto("https://www.strava.com/maps/global-heatmap"); | ||
await page.waitForResponse((response) => response.url().includes("heatmap-external")); | ||
|
||
console.log("Retrieving cookies..."); | ||
let cookies = browser.cookies(); | ||
let stravaId = cookies.find((c) => c.name === "strava_remember_id").value; | ||
let stravaCookies = cookies | ||
.filter((c) => REQUIRED_COOKIE_NAMES.includes(c.name)) | ||
.map((c) => `${c.name}=${c.value}`) | ||
.join(";"); | ||
|
||
console.log(`STRAVA_ID='${stravaId}'`); | ||
console.log(`STRAVA_COOKIES='${stravaCookies}'`); |
This file was deleted.
Oops, something went wrong.
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