Compare commits

..

152 commits
v1.6 ... main

Author SHA1 Message Date
nocci
67afeead60 chore: chown /fgc/data on start so fgc can write bind-mount
All checks were successful
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m13s
2025-12-30 17:36:31 +00:00
nocci
8ebb57a706 Add missing Playwright deps and clear Firefox locks on start
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m10s
2025-12-30 17:27:28 +00:00
nocci
949206dbf2 Ensure /tmp/.X11-unix exists with sane perms
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m16s
2025-12-30 17:21:53 +00:00
nocci
cfc1e0ee12 Harden entrypoint: skip user.js on RO volume and auto-install browsers
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 13s
build-and-push / docker (push) Successful in 1m13s
2025-12-30 17:10:53 +00:00
nocci
4d835013cc Skip browser prefs when volume is read-only
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m12s
2025-12-30 17:05:01 +00:00
nocci
6f2e1e5b22 Make browser prefs creation non-fatal when unwritable
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m11s
2025-12-30 16:58:22 +00:00
nocci
e3e6a6f36c Handle unwritable browser volume in entrypoint
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m11s
2025-12-30 16:54:42 +00:00
nocci
a477bb3327 Fix lint: guard browser globals and normalize indentation
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m12s
2025-12-30 16:47:46 +00:00
nocci
7ffc454e47 Clean up Sonar issues and lint warnings
Some checks failed
build-and-push / lint (push) Failing after 5s
build-and-push / sonar (push) Has been skipped
build-and-push / docker (push) Has been skipped
2025-12-30 16:45:17 +00:00
nocci
b9aa6e0073 Use sonar.token instead of deprecated sonar.login
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m14s
2025-12-30 16:19:53 +00:00
nocci
bab4359977 Fix indentation in unrealengine eslint
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m11s
2025-12-30 16:16:29 +00:00
nocci
52895fd991 Fix eslint no-unused-vars in async handlers
Some checks failed
build-and-push / lint (push) Failing after 4s
build-and-push / sonar (push) Has been skipped
build-and-push / docker (push) Has been skipped
2025-12-30 16:15:14 +00:00
nocci
3fd861f134 Fix eslint no-empty and clean tests
Some checks failed
build-and-push / lint (push) Failing after 4s
build-and-push / sonar (push) Has been skipped
build-and-push / docker (push) Has been skipped
2025-12-30 16:13:15 +00:00
nocci
5f919039ab Clean Sonar issues in store scripts
Some checks failed
build-and-push / lint (push) Failing after 4s
build-and-push / sonar (push) Has been skipped
build-and-push / docker (push) Has been skipped
2025-12-30 16:08:59 +00:00
nocci
397871b012 Further clean Sonar: merge base RUN, strip comments, node imports
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m13s
2025-12-30 15:47:28 +00:00
nocci
405e801851 Clean Sonar findings: merge RUNs, drop commented code, update node imports
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m13s
2025-12-30 15:39:11 +00:00
nocci
37ffd09545 Refactor prompt timeout plugin to reduce nesting
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m11s
2025-12-30 14:56:50 +00:00
nocci
69282c63d5 Address Sonar warnings and harden runtime
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m13s
2025-12-30 14:54:14 +00:00
nocci
9e2bc89ff2 chore: clean up util notify/prompt lint findings
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m11s
2025-12-30 14:36:41 +00:00
nocci
e4b1f60a66 chore: use execFile for git commands in version check
All checks were successful
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Successful in 11s
build-and-push / docker (push) Successful in 1m11s
2025-12-30 14:31:17 +00:00
nocci
f82c158a6b ci: run sonar-scanner locally instead of docker
All checks were successful
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Successful in 16s
build-and-push / docker (push) Successful in 1m10s
2025-12-30 14:27:12 +00:00
nocci
b5e9111039 ci: mount workspace explicitly for sonar scanner
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / docker (push) Successful in 1m12s
build-and-push / sonar (push) Successful in 7s
2025-12-30 14:23:43 +00:00
nocci
94be980c95 ci: debug sonar scanner mount and remove extra inclusions
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 10s
build-and-push / docker (push) Successful in 1m10s
2025-12-30 14:22:07 +00:00
nocci
00b36a65b1 ci: quote sonar inclusions to avoid shell glob
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 7s
build-and-push / docker (push) Successful in 1m8s
2025-12-30 13:25:17 +00:00
nocci
2a4653062a ci: make sonar scan pick up sources
All checks were successful
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Successful in 6s
build-and-push / docker (push) Successful in 1m10s
2025-12-30 13:22:54 +00:00
nocci
25fb2d9838 chore: remove github workflows and configs
All checks were successful
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Successful in 7s
build-and-push / docker (push) Successful in 1m13s
2025-12-30 13:19:36 +00:00
nocci
6c4eb948fc alles jut 2025-12-30 13:08:44 +00:00
nocci
405660e0f2 🐛 fix(ci): adjust sonar scm configuration
All checks were successful
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Successful in 6s
build-and-push / docker (push) Successful in 1m11s
- change sonar.scm.provider to sonar.scm.disabled for compatibility
2025-12-30 13:06:49 +00:00
nocci
02972a04d4 🐛 fix(ci): handle missing sonar project key gracefully
Some checks failed
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Failing after 6s
build-and-push / docker (push) Has been skipped
- set default empty value for PROJECT_KEY variable
- add fallback to read sonar-project.properties if secret is not provided
- exit with error if PROJECT_KEY is still unset after checks
2025-12-30 13:05:40 +00:00
nocci
608b6b87cd 👷 ci(build): simplify sonar project key retrieval
Some checks failed
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Failing after 6s
build-and-push / docker (push) Has been skipped
- remove redundant conditional logic for project key extraction
- enforce mandatory SONAR_PROJECT_KEY secret for consistency
- change sonar.scm.provider to 'none' for improved configuration
2025-12-30 13:02:52 +00:00
nocci
e11d40bdda 👷 ci(build): enforce sonar host url secret presence
Some checks failed
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Failing after 6s
build-and-push / docker (push) Has been skipped
- update HOST_URL to require SONAR_HOST_URL secret for enhanced security configuration
- improve error handling by ensuring critical secrets are set
2025-12-30 13:01:14 +00:00
nocci
8626fa5a0f ♻️ refactor(build): enhance sonar scanner configuration
- set default host url for sonar scanner to ensure consistency
- add sonar.sources and sonar.scm.provider for improved analysis
2025-12-30 12:57:44 +00:00
nocci
56ca1f63d4 👷 ci(build): enhance sonar project key configuration
Some checks failed
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Failing after 6s
build-and-push / docker (push) Has been skipped
- add SONAR_PROJECT_KEY environment variable for flexibility
- fallback to default or file-based project key if not set
2025-12-30 12:42:36 +00:00
nocci
5b1d966c6e 👷 ci(build): enhance sonar scanner configuration
Some checks failed
build-and-push / lint (push) Successful in 4s
build-and-push / sonar (push) Failing after 7s
build-and-push / docker (push) Has been skipped
- extract project key from properties file for dynamic setup
- add projectBaseDir to sonar scanner command for accurate analysis
2025-12-30 12:40:06 +00:00
nocci
d40a577f47 👷 ci(build): add SonarQube scan to build workflow
Some checks failed
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Failing after 12s
build-and-push / docker (push) Has been skipped
- introduce SonarQube scanning step for code quality analysis
- update workflow dependencies and execution order

🐛 fix(auth): improve error handling and code formatting

- remove unused imports and fix code indentation
- enhance error handling with improved catch blocks

💄 style(general): standardize code formatting and style consistency

- update various files to ensure consistent code style
- adjust indentation and whitespace for readability
2025-12-30 12:38:03 +00:00
nocci
0e5303da62 👷 ci(workflow): add lint job to build workflow
Some checks failed
build-and-push / lint (push) Failing after 32s
build-and-push / docker (push) Has been skipped
- introduce lint job in build.yml for code quality checks
- ensure lint job runs before docker job
- setup Node.js and install dependencies for ESLint
2025-12-30 11:03:08 +00:00
e39cca93c2 better README.md
All checks were successful
build-and-push / docker (push) Successful in 1m10s
2025-12-29 17:19:39 +01:00
nocci
9d79f9ac78 📝 docs(README): update configuration and remove CI section
All checks were successful
build-and-push / docker (push) Successful in 1m8s
- remove outdated CI/build instructions
- add new environment variable options for configuration

🐛 fix(util): handle notification errors gracefully

- resolve promise instead of rejecting on notification errors
- prevent whole run from failing due to notification issues
2025-12-29 15:54:41 +00:00
nocci
0a729d0cbf 🔧 chore(workflow): simplify docker image tagging and pushing
All checks were successful
build-and-push / docker (push) Successful in 1m10s
- remove specific sha tag from build and push steps
- streamline workflow by focusing on latest tag
2025-12-29 15:08:00 +00:00
nocci
eb5b9bbb6e 👷 ci(build): enhance docker build process with buildx
All checks were successful
build-and-push / docker (push) Successful in 1m12s
- add Docker Buildx setup for advanced build capabilities
- update build step to use buildx for multi-platform support
2025-12-29 15:01:55 +00:00
nocci
eba07721ca 📝 docs(README): update instructions and clarify configurations
Some checks failed
build-and-push / docker (push) Failing after 1m55s
- update registry image references to point to `git.sky-net.it/nocci/free-games-claimer`
- improve clarity on Docker and Docker Compose examples
- translate German sections into English for wider accessibility
- add detailed explanations for environment variables and configurations
- enhance quickstart and CI instructions for better understanding
2025-12-29 14:38:54 +00:00
nocci
bde0f34a80 📝 docs(README): simplify and update documentation
Some checks failed
build-and-push / docker (push) Failing after 0s
- remove detailed setup instructions and history
- add quick-start guide for Docker and Docker Compose
- update CI and configuration sections
- streamline language and formatting for clarity
2025-12-29 14:36:18 +00:00
nocci
6f778d71ac 📝 docs(README): add instructions for building images in Forgejo
Some checks failed
build-and-push / docker (push) Failing after 0s
- include steps for building and pushing Docker images using Forgejo
- provide details on setting Forgejo secrets and using self-hosted runners
2025-12-29 14:33:14 +00:00
nocci
a21dced86e 📦 build(ci): add build-and-push workflow for docker images
Some checks failed
build-and-push / docker (push) Failing after 4s
- create a new CI workflow to automate image building and pushing
- trigger workflow on push to main branch
- include steps for checkout, login, build, and push docker images
2025-12-29 14:31:25 +00:00
nocci
76f578e2e6 feat(auth): enhance automatic login and MFA handling
Some checks failed
Build and push Docker image (amd64, arm64 to hub.docker.com and ghcr.io) / docker (push) Has been cancelled
Lint / Lint (push) Has been cancelled
Sonar / sonarcloud (push) Has been cancelled
- add handleMFA function for improved two-step verification
- implement direct login page handling with automatic sign-in

🐛 fix(claim): improve game claim process and duplicate prevention

- normalize claim URLs and deduplicate by URL
- fix various selectors for claim buttons and handle different languages
- prevent duplicate game claims by checking existing records

♻️ refactor(utils): improve code readability and maintainability

- extract normalizeClaimUrl function for URL handling
- restructure logic for claim and notification processes

🌐 i18n(claim): add support for game claim text in German

- handle German text for claim buttons and status checks
2025-12-29 14:15:22 +00:00
nocci
faf22aafb1 🐛 fix(prime-gaming): update URL and selectors for claims
Some checks are pending
Build and push Docker image (amd64, arm64 to hub.docker.com and ghcr.io) / docker (push) Waiting to run
Lint / Lint (push) Waiting to run
Sonar / sonarcloud (push) Waiting to run
- change URL_CLAIM to point to new Luna claims home
- update selectors for sign-in and user verification
- improve handling of cookies acceptance

 feat(prime-gaming): enhance game claiming logic

- add support for new layout and game list detection
- implement flexible scrolling for loading all game cards
- refine logic for internal and external game claims
- improve store identification for external claims

♻️ refactor(prime-gaming): modularize game tab and list location

- extract functions for opening games tab and locating games list
- enhance code readability and maintainability

🐛 fix(prime-gaming): handle dynamic selectors for availability dates

- support multiple selectors for availability date detection
- improve error handling and logging for missing elements
2025-12-29 11:41:09 +00:00
Ralf Vogler
99c1f05302 Merge branch 'dev' 2025-05-16 00:15:45 +02:00
Ralf Vogler
991e0a1449 docker: only build branches main, dev
Otherwise branches will accumulate in 'Recent tagged image version'
https://github.com/vogler/free-games-claimer/pkgs/container/free-games-claimer
2025-05-16 00:14:10 +02:00
Ralf Vogler
cea5b11c95 mv renovate.json .github/ 2025-05-16 00:06:39 +02:00
Ralf Vogler
6adc7e529a disable Renovate for now 2025-05-16 00:05:48 +02:00
Ralf Vogler
158caa6164
Merge pull request #469 from vogler/renovate/super-linter-super-linter-7.x 2025-05-16 00:01:31 +02:00
Ralf Vogler
0a4cac3571 ncu -u 2025-05-15 23:51:49 +02:00
Ralf Vogler
bf0c9032cc need 'packages: write' permission for ghcr.io 2025-05-14 01:59:37 +02:00
Ralf Vogler
4ce0d44b79 can't check secrets in if expr... 2025-05-14 01:44:14 +02:00
Ralf Vogler
7c8682ac91 build docker image for each branch/PR? 2025-05-14 01:31:04 +02:00
Ralf Vogler
a5ce5ec816 fix CodeQL alerts 5-7
https://github.com/vogler/free-games-claimer/security/code-scanning/5
https://github.com/vogler/free-games-claimer/security/code-scanning/6
https://github.com/vogler/free-games-claimer/security/code-scanning/7
2025-05-14 00:46:37 +02:00
Ralf Vogler
6aea18836d enquirer: esc is fine, but after first prompt SIGINT will be ignore; onRawSIGINT keeps process running -> switch to inquirer 2025-05-14 00:30:39 +02:00
Ralf Vogler
97ef14f514 uncommited steam-games.js from 2024-09-24 - WIP just saves all games and their stats 2025-05-14 00:18:22 +02:00
Ralf Vogler
5cfe57870a note on git describe for version 2025-05-13 23:43:29 +02:00
renovate[bot]
3e13e9fba8
chore(deps): update super-linter/super-linter action to v7.4.0 2025-05-13 20:29:21 +00:00
Ralf Vogler
dee47d2218 pg: redeem gog: detect captcha 2025-04-15 17:27:21 +02:00
Ralf Vogler
726db4527b Current free game title in blue 2025-04-15 17:26:27 +02:00
Ralf Vogler
04d1b7ea9e pg: fix auto-login; rememberMe was removed 2025-04-15 17:22:21 +02:00
Ralf Vogler
0fefcc47b7 pg: skipBasedOnTime if days left > PG_TIMELEFT 2025-04-15 17:08:34 +02:00
Ralf Vogler
92cb32ff2d ae: try fingerprint-injector 2025-04-03 15:33:00 +02:00
Ralf Vogler
90e3400072
readme: logos: use GitHub asset upload 2025-03-27 17:11:30 +01:00
Ralf Vogler
041a77d9f6
readme: logos: align: middle - CSS is stripped 2025-03-27 17:01:18 +01:00
Ralf Vogler
787522473f readme: logos: vertical-align: middle 2025-03-27 16:53:41 +01:00
Ralf Vogler
cfe42db805 pg: fix logo 2025-03-27 16:53:27 +01:00
Ralf Vogler
8b7018f54c fix actionlint errors (docker.yml)
Double quote to prevent globbing and word splitting
2025-03-27 16:26:40 +01:00
Ralf Vogler
ea69c76b50 eg: fix #449: only notify once if 'Game already in library' 2025-03-11 10:14:42 +01:00
Ralf Vogler
3626fc1762 fixup #417 2025-03-05 16:17:48 +01:00
Ralf Vogler
d2d85dee8c
Merge pull request #417 from NeoMod/patch-1
Fixed missing game link in notification for epic-games on captcha halt
2025-03-05 16:11:37 +01:00
Ralf Vogler
8d538290a8
Merge pull request #387 from srounce/patch-1
fix: docker-entrypoint.sh uses safe shebang
2025-03-05 15:57:54 +01:00
Ralf Vogler
daef12b562
Merge pull request #441 from vogler/renovate/docker-build-push-action-6.x
chore(deps): update docker/build-push-action action to v6
2025-03-05 15:54:29 +01:00
Ralf Vogler
acaf6691d4
Merge pull request #440 from vogler/renovate/major-eslint-stylistic-monorepo
chore(deps): update dependency @stylistic/eslint-plugin-js to v4
2025-03-05 15:54:12 +01:00
renovate[bot]
e75975b273
chore(deps): update docker/build-push-action action to v6 2025-03-05 14:54:01 +00:00
renovate[bot]
cb22abfb2f
chore(deps): update dependency @stylistic/eslint-plugin-js to v4 2025-03-05 14:53:57 +00:00
Ralf Vogler
67058850d5
Merge pull request #438 from vogler/renovate/chalk-5.x-lockfile
fix(deps): update dependency chalk to v5.4.1
2025-03-05 15:47:47 +01:00
Ralf Vogler
3ac05a5593
Merge pull request #434 from vogler/renovate/eslint-stylistic-monorepo
chore(deps): update dependency @stylistic/eslint-plugin-js to v2.13.0
2025-03-05 15:47:30 +01:00
renovate[bot]
d620ee2731
chore(deps): update dependency @stylistic/eslint-plugin-js to v2.13.0 2025-03-05 14:46:12 +00:00
Ralf Vogler
f47ffe0e9f
Merge pull request #436 from vogler/renovate/eslint-monorepo
chore(deps): update dependency eslint to v9.21.0
2025-03-05 15:45:33 +01:00
Ralf Vogler
253a3f7253
Merge pull request #433 from vogler/renovate/dotenv-16.x-lockfile
fix(deps): update dependency dotenv to v16.4.7
2025-03-05 15:44:52 +01:00
Ralf Vogler
5e5c257b83
Merge pull request #437 from vogler/super-linter
try super-linter
2025-03-05 15:41:35 +01:00
Ralf Vogler
6aa0f9b817 super-linter: problem matchers included? 2025-03-05 15:34:03 +01:00
Ralf Vogler
bf2216f731 super-linter: TODO fix-lint-issues 2025-03-05 15:27:00 +01:00
Ralf Vogler
d6666aed03 super-linter: use slim version 2025-03-05 15:17:34 +01:00
renovate[bot]
041605dcf7
fix(deps): update dependency chalk to v5.4.1 2025-03-05 14:08:35 +00:00
renovate[bot]
d76c03ed6a
chore(deps): update dependency eslint to v9.21.0 2025-03-05 14:08:28 +00:00
Ralf Vogler
fed03428f3 try super-linter
https://github.com/marketplace/actions/super-linter#get-started
2025-03-05 15:07:37 +01:00
renovate[bot]
4a018c20e9
fix(deps): update dependency dotenv to v16.4.7 2025-03-05 13:22:40 +00:00
Ralf Vogler
ceb873ea0b
Merge pull request #432 from vogler/renovate/configure
chore: Configure Renovate
2025-03-05 14:22:06 +01:00
renovate[bot]
9e87ce58ac
Add renovate.json 2025-03-05 13:17:13 +00:00
NeoMod
b3ab8f7830
Fixed missing game link in notification for epic-games on captcha halt
This fixes the "game link" missing from notification when checking Epic Games Store and encountering a captcha, as per #259 should have been but instead wasn't. Issue was identified in #402 comment by "vttc08" (https://github.com/vogler/free-games-claimer/issues/402#issuecomment-2510818082)

I also added the missing notification for "Game Already in Library" for Epic Games Store, since I felt it is useful because it provides an easy way to know if the script is working or not during scheduled usage.

This also provided the opportunity to check if the game url link was handled properly outside "Discord": I have added a commented option where one could activate the "Already in Library" notification that will also provide the game url link for easy verification.
2025-01-01 15:31:04 +01:00
Ralf Vogler
33d2493336
Merge pull request #411 from AgentTechnoman/main
Fix gog error per @jordyamc
2024-12-30 04:29:09 +01:00
AgentTechnoman
d5072a62c0
Fix gog error per @jordyamc
https://github.com/vogler/free-games-claimer/issues/398#issuecomment-2487274414
2024-12-19 16:46:18 -07:00
Samuel Rounce
c5a7a10ca3
fix: docker-entrypoint.sh uses safe shebang
Shebangs should use /usr/bin/env to locate the interpreter. Setting a path directly to the interpreter itself tends to be brittle and prone to breaking.
2024-09-28 18:34:39 +01:00
Ralf Vogler
c8cf7362fa eg: wait for purchaseBtn to have some text, fixes #375 2024-09-01 01:20:45 +02:00
Ralf Vogler
fef5b97e3b eg: wait for purchaseBtn, without it didn't detect bundle as already claimed 2024-08-29 20:23:43 +02:00
Ralf Vogler
292aadae3c eg: list games included in a bundle 2024-08-29 20:06:59 +02:00
Ralf Vogler
7279ba06e8 eg: change back to purchase-cta-button from 'aside button', fixes #374 2024-08-29 19:48:28 +02:00
Ralf Vogler
1f4af79e0e pg: fix loading all games by 2*PageDown + checking height instead of End + checking count..., #357 2024-08-29 13:23:45 +02:00
Ralf Vogler
c8e0640490 eg: #371: dump HTML in case of EULA popup to find new locator
https://github.com/vogler/free-games-claimer/issues/371
2024-08-29 12:46:28 +02:00
Ralf Vogler
eafb2316f7 pg: login now has Continue button after email 2024-08-28 02:31:47 +02:00
Ralf Vogler
c87deb393e pg: DLC: forgot to await scrollUntilStable, closes #356 2024-08-02 14:02:33 +02:00
Ralf Vogler
23a611a2f1 ci/docker: fix: tag main as latest 2024-08-02 13:19:39 +02:00
Ralf Vogler
eac11e8949 ci/docker: force tag main as latest since many people pull it 2024-08-02 13:06:28 +02:00
Ralf Vogler
8605b70377 pg: fix internal/external locators, closes #355, waitUntilStable 2s -> 5s 2024-08-02 12:57:37 +02:00
Ralf Vogler
d9e91d22c9 eg: fix changed button locators 2024-08-01 15:46:41 +02:00
Ralf Vogler
a39d737999 aliexpress: collect daily coins via desktop website
All load in webview in android app.
Other games have no desktop version and mobile version uses canvas
and only refers to download app with both stealth and fingerprint-injector.
Also stuck on loading screen when using firefox instead of chrome.
2024-07-19 14:35:40 +02:00
Ralf Vogler
b8f7068a87 pg: scrollUntilStable to wait in loop to load all games since one scroll may not be enough 2024-07-10 13:27:48 +02:00
Ralf Vogler
17f1ee41c9 eg: don't exit on login error since it may be 'Incorrect response' for captcha
https://github.com/vogler/free-games-claimer/issues/183#issuecomment-2195691372
2024-06-27 23:32:15 +02:00
Ralf Vogler
aee72327ea eg: disable webgl since it leaks running virtualized, #183 2024-06-27 15:41:58 +02:00
Ralf Vogler
00275d825b eg: forgot to catch timeout for captcha detection 2024-06-27 15:40:45 +02:00
Ralf Vogler
e154b74e4d eg: TODO handle base game for add-ons via function 2024-06-27 14:09:37 +02:00
Ralf Vogler
d85cd8d20c rm xbox.js, no more games with gold, closes #286, closes #339
TODO integrate login code for microsoft games in prime-gaming
2024-06-27 10:54:46 +02:00
Ralf Vogler
9af36e902c eg: fix login: password now together with email again, detect login error, closes #338, closes #337 2024-06-26 17:16:38 +02:00
Ralf Vogler
920fc4d186
Merge pull request #318 from Targunitoth/main
Escape the apprise -b parameter
2024-06-25 18:52:13 +02:00
Ralf Vogler
c4be7ece21 xbox: fixup #307 2024-06-25 18:45:21 +02:00
Ralf Vogler
b8071d442c
Merge pull request #307 from Rexexe/main
Resolve error with no default data
2024-06-25 18:44:25 +02:00
Ralf Vogler
9cf5d2f7f2 pg: include code in redeem_url for gog, closes #330 2024-06-25 15:50:02 +02:00
Ralf Vogler
55226933c0 filenamify datetime recordHar for Windows : -> ., fix #336 2024-06-25 15:30:02 +02:00
Ralf Vogler
357a780aa9
Merge pull request #325 from Tymec/main
Ability to use a different email for Legacy Games
2024-06-25 13:31:06 +02:00
Ralf Vogler
afceb0aad9
Merge branch 'main' into main 2024-06-25 13:30:42 +02:00
Ralf Vogler
c0eb6dbb0b ncu -u: playwright 1.44.1 -> 1.45.0 2024-06-25 13:24:55 +02:00
Ralf Vogler
076738e301 gog: fail if WIDTH<1280 due to hidden username, closes #335 2024-06-25 13:09:10 +02:00
Ralf Vogler
601e893714 README: link example how to set env vars on Windows, closes #314 2024-06-23 20:50:00 +02:00
Ralf Vogler
43bef9b23c pg: redeem microsoft store and xbox, WIP, #315, #5 2024-06-23 20:44:03 +02:00
Ralf Vogler
f920aa26d0 pg: checkTimeLeft via PG_TIMELEFT=1 2024-06-23 19:18:30 +02:00
Ralf Vogler
30b1835bdb pg: reverse games: oldest/bottom to newest/top 2024-06-23 19:16:01 +02:00
Ralf Vogler
f0f142733e ncu -u: lowdb 6 -> 7 dropped support for Node 16 2024-06-23 19:14:13 +02:00
Ralf Vogler
cf59da5d9e gog: new locators, fixes #326, #334 2024-06-23 18:03:38 +02:00
Ralf Vogler
2d81ed2145
Merge pull request #329 from nett00n/patch-1
Update README.md
2024-06-21 18:12:04 +02:00
Vladimir Budylnikov
f7c23569c7
Update README.md
I've made i howto for windows users
2024-06-02 13:33:51 +04:00
Ralf Vogler
9ef9798626 eg: detect 'Failed to challenge captcha, please try again later.' 2024-05-23 15:55:07 +02:00
Ralf Vogler
e49fa930e0 eg: claim base game before add-on 2024-05-23 15:54:23 +02:00
Tymec
c4ae3505b3
Update README.md 2024-05-18 19:50:13 +02:00
Tymec
8c535f48fa
Update prime-gaming.js 2024-05-18 19:47:18 +02:00
Tymec
075106da11
Update config.js 2024-05-18 19:45:59 +02:00
Ralf Vogler
3338d08a1d eg: fix title for Bundles, TODO got stuck after
happened for 'LISA: The Definitive Edition' - https://store.epicgames.com/en-US/bundles/lisa-the-definitive-edition
2024-05-02 16:58:31 +02:00
Targunitoth
da6964c19a
Escape the apprise -b parameter 2024-04-25 13:51:40 +02:00
Ralf Vogler
6f06fccd46 eslint: prefer-const 2024-03-07 13:47:58 +01:00
Rex
61fdf566c9 Resolve error with no default data 2024-03-01 20:57:00 +08:00
Ralf Vogler
285c7a44fd README.md: comment alternative starchart.cc 2024-02-29 16:35:02 +01:00
Ralf Vogler
2ea0c611e4 pg: fix claiming external games, detect store early in description, delete old code 2024-02-13 23:48:48 +01:00
Ralf Vogler
e4e4ce703d pg: also get and store url for internal games 2024-02-13 23:45:36 +01:00
Ralf Vogler
fc810af80e
Update README.md: add Repobeats insights 2024-01-11 15:58:56 +01:00
Ralf Vogler
28bcceb285 eg: enter date of birth if age confirmation pops up, #275 2023-12-31 16:58:56 +01:00
Ralf Vogler
0ec24ef062 fix import paths for test/ 2023-12-30 13:37:04 +01:00
Ralf Vogler
c3657f05ac workaround for cropped viewport (Playwright regression), fixes #277 2023-12-28 17:56:09 +01:00
Ralf Vogler
7ca79bd413 eg: debug window.screen 2023-12-28 17:31:23 +01:00
Ralf Vogler
56cfab6e21
Update README.md 2023-12-28 11:28:23 +01:00
26 changed files with 3717 additions and 1505 deletions

View file

@ -0,0 +1,87 @@
name: build-and-push
on:
push:
branches:
- main
jobs:
lint:
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
sonar:
needs: lint
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Sonar Scanner (npm)
run: npm install -g sonarqube-scanner
- name: SonarQube Scan
env:
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_PROJECT_KEY: ${{ secrets.SONAR_PROJECT_KEY }}
run: |
WORKDIR=${GITHUB_WORKSPACE:-$PWD}
HOST_URL=${SONAR_HOST_URL:?SONAR_HOST_URL secret not set}
PROJECT_KEY=${SONAR_PROJECT_KEY:-}
if [ -z "$PROJECT_KEY" ] && [ -f sonar-project.properties ]; then
PROJECT_KEY=$(grep -E '^sonar.projectKey=' sonar-project.properties | cut -d= -f2 | tr -d '\r')
fi
if [ -z "$PROJECT_KEY" ]; then
echo "SONAR_PROJECT_KEY secret not set and no sonar-project.properties entry found" >&2
exit 1
fi
echo "Sonar project key: $PROJECT_KEY"
echo "Listing workspace:"
ls -la
echo "Sample files:"
find . -maxdepth 2 -type f | head -n 20
echo "Running local sonar-scanner..."
sonar-scanner \
-Dsonar.host.url="$HOST_URL" \
-Dsonar.token="$SONAR_TOKEN" \
-Dsonar.projectKey="$PROJECT_KEY" \
-Dsonar.sources=. \
-Dsonar.scm.disabled=true \
-Dsonar.projectBaseDir="$WORKDIR"
docker:
needs: [lint, sonar]
runs-on: self-hosted
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout
uses: actions/checkout@v4
- name: Login to registry
run: echo "${{ secrets.REG_TOKEN }}" | docker login "${{ secrets.REGISTRY }}" -u "${{ secrets.REG_USER }}" --password-stdin
- name: Build image
run: |
docker buildx build --load \
-t "${{ secrets.REGISTRY_IMAGE }}:latest" .
- name: Push image
run: |
docker push "${{ secrets.REGISTRY_IMAGE }}:latest"

13
.github/FUNDING.yml vendored
View file

@ -1,13 +0,0 @@
# These are supported funding model platforms
github: vogler # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: fgc # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: vogler # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: vogler # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ["https://www.buymeacoffee.com/vogler", "https://paypal.me/voglerr"] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View file

@ -1,28 +0,0 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
# commit-message:
# prefix: "npm"
# include: "scope"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
# commit-message:
# prefix: "docker"
# include: "scope"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
# commit-message:
# prefix: "github-actions"
# include: "scope"

View file

@ -1,74 +0,0 @@
name: Build and push Docker image (amd64, arm64 to hub.docker.com and ghcr.io)
on:
workflow_dispatch: # allow manual trigger
# https://github.com/orgs/community/discussions/26276
push:
branches:
- "main"
- "v*"
tags:
- "v*"
paths: # ignore changes to certain files
- '**'
- '!*.md'
# - '!.github/**'
pull_request: # runs when opened/reopned or when the head branch is updated, see https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
branches:
- "main" # only PRs against main
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Set environment variables
run: |
echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "NOW=$(date -R)" >> $GITHUB_ENV # date -Iseconds; date +'%Y-%m-%dT%H:%M:%S'
if [[ "${{ env.BRANCH }}" == "main" ]]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
else
echo "IMAGE_TAG=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
fi
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to Docker Hub
uses: docker/login-action@v3
if: github.event_name != 'pull_request' # TODO if DOCKERHUB_* are set?
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }} # actor is user that opened PR, was repository_owner before
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
# if: github.event_name != 'pull_request' # still want to build image
with:
context: .
push: ${{ github.event_name != 'pull_request' }} # TODO push for forks?
build-args: |
COMMIT=${{ github.sha }}
BRANCH=${{ env.BRANCH }}
NOW=${{ env.NOW }}
platforms: linux/amd64,linux/arm64 # ,linux/arm/v7
# TODO docker tag only if DOCKERHUB_* are set?
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/free-games-claimer:${{env.IMAGE_TAG}}
ghcr.io/${{ github.actor }}/free-games-claimer:${{env.IMAGE_TAG}}
cache-from: type=gha
cache-to: type=gha,mode=max

View file

@ -1,37 +0,0 @@
on:
# Trigger analysis when pushing in main or pull requests, and when creating a pull request.
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
name: Sonar
jobs:
sonarcloud:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v4
with:
# Disabling shallow clone is recommended for improving relevancy of reporting. Otherwise sonarcloud will show a warning.
fetch-depth: 0
-
uses: actions/setup-node@v4
with:
cache: 'npm'
-
name: Install dev dependencies which includde ESLint + plugins
run: npm install --only=dev
-
name: Run ESLint
continue-on-error: true
run: npx eslint . -f json -o eslint_report.json
-
name: Fix ESLint paths
run: sed -i 's+/home/runner/work/free-games-claimer/free-games-claimer+/github/workspace+g' eslint_report.json
-
name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

View file

@ -23,8 +23,6 @@ RUN apt-get update \
novnc websockify \ novnc websockify \
dos2unix \ dos2unix \
python3-pip \ python3-pip \
# && npx playwright install-deps firefox \
&& apt-get install --no-install-recommends -y \
libgtk-3-0 \ libgtk-3-0 \
libasound2 \ libasound2 \
libxcomposite1 \ libxcomposite1 \
@ -36,6 +34,9 @@ RUN apt-get update \
libgdk-pixbuf-2.0-0 \ libgdk-pixbuf-2.0-0 \
libdbus-glib-1-2 \ libdbus-glib-1-2 \
libxcursor1 \ libxcursor1 \
libnss3 \
libnspr4 \
libgbm1 \
&& apt-get autoremove -y \ && apt-get autoremove -y \
&& apt-get clean \ && apt-get clean \
&& rm -rf \ && rm -rf \
@ -43,13 +44,10 @@ RUN apt-get update \
/usr/share/doc/* \ /usr/share/doc/* \
/var/cache/* \ /var/cache/* \
/var/lib/apt/lists/* \ /var/lib/apt/lists/* \
/var/tmp/* /var/tmp/* \
&& useradd -ms /bin/bash fgc \
# RUN node --version && ln -s /usr/share/novnc/vnc_auto.html /usr/share/novnc/index.html \
# RUN npm --version && pip install apprise
RUN ln -s /usr/share/novnc/vnc_auto.html /usr/share/novnc/index.html
RUN pip install apprise
WORKDIR /fgc WORKDIR /fgc
COPY package*.json ./ COPY package*.json ./
@ -61,10 +59,15 @@ RUN npm install
# From 1.38 Playwright will no longer install browser automatically for playwright, but apparently still for playwright-firefox: https://github.com/microsoft/playwright/releases/tag/v1.38.0 # From 1.38 Playwright will no longer install browser automatically for playwright, but apparently still for playwright-firefox: https://github.com/microsoft/playwright/releases/tag/v1.38.0
# RUN npx playwright install firefox # RUN npx playwright install firefox
COPY . . # Only copy the files we actually need in the image to avoid accidentally adding secrets.
COPY *.js ./
COPY eslint.config.js jsconfig.json sonar-project.properties ./
COPY src ./src
COPY test ./test
COPY docker-entrypoint.sh ./
# Shell scripts need Linux line endings. On Windows, git might be configured to check out dos/CRLF line endings, so we convert them for those people in case they want to build the image. They could also use --config core.autocrlf=input # Shell scripts need Linux line endings. On Windows, git might be configured to check out dos/CRLF line endings, so we convert them for those people in case they want to build the image. They could also use --config core.autocrlf=input
RUN dos2unix ./*.sh && chmod +x ./*.sh RUN dos2unix ./*.sh && chmod +x ./*.sh && chown -R fgc:fgc /fgc
COPY docker-entrypoint.sh /usr/local/bin/ COPY docker-entrypoint.sh /usr/local/bin/
ARG COMMIT="" ARG COMMIT=""
@ -87,8 +90,9 @@ LABEL org.opencontainers.image.title="free-games-claimer" \
# Configure VNC via environment variables: # Configure VNC via environment variables:
ENV VNC_PORT 5900 ENV VNC_PORT 5900
ENV NOVNC_PORT 6080 ENV NOVNC_PORT 6080
EXPOSE 5900 # Ports are not exposed by default; publish explicitly with -p when you really need GUI access.
EXPOSE 6080 # EXPOSE 5900
# EXPOSE 6080
# Configure Xvfb via environment variables: # Configure Xvfb via environment variables:
ENV WIDTH 1920 ENV WIDTH 1920
@ -98,6 +102,8 @@ ENV DEPTH 24
# Show browser instead of running headless # Show browser instead of running headless
ENV SHOW 1 ENV SHOW 1
USER fgc
# Script to setup display server & VNC is always executed. # Script to setup display server & VNC is always executed.
ENTRYPOINT ["docker-entrypoint.sh"] ENTRYPOINT ["docker-entrypoint.sh"]
# Default command to run. This is replaced by appending own command, e.g. `docker run ... node prime-gaming` to only run this script. # Default command to run. This is replaced by appending own command, e.g. `docker run ... node prime-gaming` to only run this script.

286
README.md
View file

@ -1,220 +1,88 @@
<p align="center"> Free Games Claimer (Fork)
<img alt="logo-free-games-claimer" src="https://user-images.githubusercontent.com/493741/214588518-a4c89998-127e-4a8c-9b1e-ee4a9d075715.png" /> ==========================
</p>
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=vogler_free-games-claimer&metric=code_smells)](https://sonarcloud.io/project/overview?id=vogler_free-games-claimer) [![Quality Gate Status](https://sonata.cyber77.de/api/project_badges/measure?project=free-games-claimer&metric=alert_status&token=sqb_99c83edf82a1331f0c649f8a5b698b4ec8f9a965)](https://sonata.cyber77.de/dashboard?id=free-games-claimer)
# free-games-claimer
Claims free games periodically on Automates claiming of free games for:
- <img src="https://upload.wikimedia.org/wikipedia/commons/3/31/Epic_Games_logo.svg" width="32"/> [Epic Games Store](https://www.epicgames.com/store/free-games) - Amazon Luna Gaming / Luna claims (including external stores like GOG, Epic Games, Legacy Games )
- <img src="https://seeklogo.com/images/P/prime-gaming-logo-61A701B3F5-seeklogo.com.png" width="32"/> [Amazon Prime Gaming](https://gaming.amazon.com) - GOG giveaways
- <img src="https://static.wikia.nocookie.net/this-war-of-mine/images/1/1a/Logo_GoG.png/revision/latest?cb=20160711062658" width="32"/> [GOG](https://www.gog.com) - Optional extras: Steam stats, AliExpress dailies (not implemated yet)
- <img src="https://cdn2.unrealengine.com/ue-logo-white-e34b6ba9383f.svg" width="32"/> [Unreal Engine (Assets)](https://www.unrealengine.com/marketplace/en-US/assets?count=20&sortBy=effectiveDate&sortDir=DESC&start=0&tag=4910) ([experimental](https://github.com/vogler/free-games-claimer/issues/44), same login as Epic Games)
<!-- - <img src="https://www.freepnglogos.com/uploads/xbox-logo-picture-png-14.png" width="32"/> [Xbox Live Games with Gold](https://www.xbox.com/en-US/live/gold#gameswithgold) ([experimental](https://github.com/vogler/free-games-claimer/issues/19)) -->
Pull requests welcome :) Requirements
------------
- Docker or Podman (recommended), or Node.js ≥ 20 for local runs
- Optional notifications: `pip install apprise`
- Playwright dependencies are baked into the container; locally, `npm install` downloads Firefox.
![Telegram Screenshot](https://user-images.githubusercontent.com/493741/214667078-eb5c1877-2bdd-40c1-b94e-4a50d6852c06.png) Quickstart (Docker Run)
-----------------------
_Works on Windows/macOS/Linux._
Raspberry Pi (3, 4, Zero 2): [requires 64-bit OS](https://github.com/vogler/free-games-claimer/issues/3) like Raspberry Pi OS or Ubuntu (Raspbian won't work since it's 32-bit).
## How to run
Easy option: [install Docker](https://docs.docker.com/get-docker/) (or [podman](https://podman-desktop.io/)) and run this command in a terminal (Windows: `cmd`, `.bat` file):
``` ```
docker run --rm -it -p 6080:6080 -v fgc:/fgc/data --pull=always ghcr.io/vogler/free-games-claimer docker run --rm -it \
-p 6080:6080 \
-v fgc:/fgc/data \
-e SHOW=1 \
git.sky-net.it/nocci/free-games-claimer:latest \
node prime-gaming.js
```
- Ports 6080/5900: noVNC/VNC (only needed with `SHOW=1`)
- Data/configs are stored in volume `fgc` under `/fgc/data`
Docker Compose Example
----------------------
```yaml
services:
fgc:
image: git.sky-net.it/nocci/free-games-claimer:latest
container_name: fgc
environment:
- SHOW=1 # show browser via VNC/noVNC
# - PG_EMAIL=...
# - PG_PASSWORD=...
# - PG_OTPKEY=...
volumes:
- fgc:/fgc/data
ports:
- "6080:6080" # noVNC
# - "5900:5900" # VNC optional
command: bash -c "node epic-games; node prime-gaming; node gog"
volumes:
fgc:
``` ```
_This currently gives you a captcha challenge for epic-games. Until [issue #183](https://github.com/vogler/free-games-claimer/issues/183) is fixed, it is recommended to just run `node epic-games` without docker (see below)._ Configuration (Environment Variables)
-------------------------------------
Common options:
- `SHOW=0/1` (0 = headless, 1 = UI)
- `WIDTH`, `HEIGHT` (browser size)
- `TIMEOUT`, `LOGIN_TIMEOUT` (seconds)
- Login: `EMAIL`, `PASSWORD` global; per store `EG_EMAIL`, `EG_PASSWORD`, `EG_OTPKEY`, `PG_EMAIL`, `PG_PASSWORD`, `PG_OTPKEY`, `GOG_EMAIL`, `GOG_PASSWORD`
- Prime Gaming: `PG_REDEEM=1` (auto-redeem keys, experimental), `PG_CLAIMDLC=1`, `PG_TIMELEFT=<days>` to skip long-remaining offers
- Screenshots: `SCREENSHOTS_DIR` (default `data/screenshots`)
- Notifications: `NOTIFY='...'` (Apprise URL), optional `NOTIFY_TITLE`
- Browser profile: `BROWSER_DIR` (default `data/browser`)
- Recording: `RECORD=1` to save videos/HAR to `data/record/`
- Debugging: `DEBUG=1` (opens Playwright inspector), `DEBUG_NETWORK=1` (logs requests), `TIME=1` (prints timings)
- Dry run / Interaction: `DRYRUN=1` (do not claim), `INTERACTIVE=1` (ask before claiming), `HEADLESS` is derived from `SHOW`/`DEBUG`
- Directories: `SCREENSHOTS_DIR`, `BROWSER_DIR`, `DATA_DIR` (prefix for data; default under `data/`)
- VNC/noVNC: `VNC_PASSWORD` (for Docker entrypoint), `NOVNC_PORT`/`VNC_PORT` (Docker)
- General timeouts: `TIMEOUT` (per action), `LOGIN_TIMEOUT` (extra time for login)
This will run `node epic-games; node prime-gaming; node gog` - if you only want to claim games for one of the stores, you can override the default command by appending e.g. `node epic-games` at the end of the `docker run` command, or if you want several `bash -c "node epic-games.js; node gog.js"`. You can place a `data/config.env`; it is loaded via dotenv and is overridden by explicitly set environment variables.
Data (including json files with claimed games, codes to redeem, screenshots) is stored in the Docker volume `fgc`.
<details> Local Run Without Docker
<summary>I want to run without Docker or develop locally.</summary> ------------------------
```
npm install
SHOW=0 PG_EMAIL=... PG_PASSWORD=... PG_OTPKEY=... node prime-gaming.js
```
- Playwright downloads Firefox to `~/.cache/ms-playwright`.
- Use `SHOW=1` for a visible browser (requires GUI/Xvfb).
1. [Install Node.js](https://nodejs.org/en/download) Persistence & Outputs
2. Clone/download this repository and `cd` into it in a terminal ---------------------
3. Run `npm install` - Data/status: `data/*.json` (per store)
4. Run `pip install apprise` (or use [pipx](https://github.com/pypa/pipx) if you have [problems](https://stackoverflow.com/questions/75608323/how-do-i-solve-error-externally-managed-environment-every-time-i-use-pip-3)) to install [apprise](https://github.com/caronc/apprise) if you want notifications - Browser profile: `data/browser`
5. To get updates: `git pull; npm install` - Screenshots: `data/screenshots/<store>/`
6. Run `node epic-games`, `node prime-gaming`, `node gog`... - Optional videos/HAR: `RECORD=1``data/record/`
During `npm install` Playwright will download its Firefox to a cache in home ([doc](https://playwright.dev/docs/browsers#managing-browser-binaries)). Tip: For captchas or first-time login, run with `SHOW=1` and log in once; cookies stay in the profile. Notifications via `NOTIFY` help surface errors (e.g., captcha, login).
If you are missing some dependencies for the browser on your system, you can use `sudo npx playwright install firefox --with-deps`.
If you don't want to use Docker for quasi-headless mode, you could run inside a virtual machine, on a server, or you wake your PC at night to avoid being interrupted.
</details>
## Usage
All scripts start an automated Firefox instance, either with the browser GUI shown or hidden (*headless mode*). By default, you won't see any browser open on your host system.
- When running inside Docker, the browser will be shown only inside the container. You can open http://localhost:6080 to interact with the browser running inside the container via noVNC (or use other VNC clients on port 5900).
- When running the scripts outside of Docker, the browser will be hidden by default; you can use `SHOW=1 ...` to show the UI (see options below).
When running the first time, you have to login for each store you want to claim games on.
You can login indirectly via the terminal or directly in the browser. The scripts will wait until you are successfully logged in.
There will be prompts in the terminal asking you to enter email, password, and afterwards some OTP (one time password / security code) if you have 2FA/MFA (two-/multi-factor authentication) enabled. If you want to login yourself via the browser, you can press escape in the terminal to skip the prompts.
After login, the script will continue claiming the current games. If it still waits after you are already logged in, you can restart it (and open an issue). If you run the scripts regularly, you should not have to login again.
### Configuration / Options
Options are set via [environment variables](https://kinsta.com/knowledgebase/what-is-an-environment-variable/) which allow for flexible configuration.
TODO: ~~On the first run, the script will guide you through configuration and save all settings to `data/config.env`. You can edit this file directly or run `node fgc config` to run the configuration assistant again.~~
Available options/variables and their default values:
| Option | Default | Description |
|--------------- |--------- |------------------------------------------------------------------------ |
| SHOW | 1 | Show browser if 1. Default for Docker, not shown when running outside. |
| WIDTH | 1280 | Width of the opened browser (and of screen for VNC in Docker). |
| HEIGHT | 1280 | Height of the opened browser (and of screen for VNC in Docker). |
| VNC_PASSWORD | | VNC password for Docker. No password used by default! |
| NOTIFY | | Notification services to use (Pushover, Slack, Telegram...), see below. [Apprise](https://github.com/caronc/apprise) |
| NOTIFY_TITLE | | Optional title for notifications, e.g. for Pushover. |
| BROWSER_DIR | data/browser | Directory for browser profile, e.g. for multiple accounts. |
| TIMEOUT | 60 | Timeout for any page action. Should be fine even on slow machines. |
| LOGIN_TIMEOUT | 180 | Timeout for login in seconds. Will wait twice (prompt + manual login). |
| EMAIL | | Default email for any login. |
| PASSWORD | | Default password for any login. |
| EG_EMAIL | | Epic Games email for login. Overrides EMAIL. |
| EG_PASSWORD | | Epic Games password for login. Overrides PASSWORD. |
| EG_OTPKEY | | Epic Games MFA OTP key. |
| EG_PARENTALPIN | | Epic Games Parental Controls PIN. |
| PG_EMAIL | | Prime Gaming email for login. Overrides EMAIL. |
| PG_PASSWORD | | Prime Gaming password for login. Overrides PASSWORD. |
| PG_OTPKEY | | Prime Gaming MFA OTP key. |
| PG_REDEEM | 0 | Prime Gaming: try to redeem keys on external stores ([experimental](https://github.com/vogler/free-games-claimer/issues/5)). |
| PG_CLAIMDLC | 0 | Prime Gaming: try to claim DLCs ([experimental](https://github.com/vogler/free-games-claimer/issues/55)). |
| GOG_EMAIL | | GOG email for login. Overrides EMAIL. |
| GOG_PASSWORD | | GOG password for login. Overrides PASSWORD. |
| GOG_NEWSLETTER | 0 | Do not unsubscribe from newsletter after claiming a game if 1. |
See `src/config.js` for all options.
#### How to set options
You can add options directly in the command or put them in a file to load.
##### Docker
You can pass variables using `-e VAR=VAL`, for example `docker run -e EMAIL=foo@bar.baz -e NOTIFY='tgram://bottoken/ChatID' ...` or using `--env-file fgc.env` where `fgc.env` is a file on your host system (see [docs](https://docs.docker.com/engine/reference/commandline/run/#env)). You can also `docker cp` your configuration file to `/fgc/data/config.env` in the `fgc` volume to store it with the rest of the data instead of on the host ([example](https://github.com/moby/moby/issues/25245#issuecomment-365980572)).
If you are using [docker compose](https://docs.docker.com/compose/environment-variables/) (or Portainer etc.), you can put options in the `environment:` section.
##### Without Docker
On Linux/macOS you can prefix the variables you want to set, for example `EMAIL=foo@bar.baz SHOW=1 node epic-games` will show the browser and skip asking you for your login email.
You can also put options in `data/config.env` which will be loaded by [dotenv](https://github.com/motdotla/dotenv).
### Notifications
The scripts will try to send notifications for successfully claimed games and any errors like needing to log in or encountered captchas (should not happen).
[apprise](https://github.com/caronc/apprise) is used for notifications and offers many services including Pushover, Slack, Telegram, SMS, Email, desktop and custom notifications.
You just need to set `NOTIFY` to the notification services you want to use, e.g. `NOTIFY='mailto://myemail:mypass@gmail.com' 'pbul://o.gn5kj6nfhv736I7jC3cj3QLRiyhgl98b'` - refer to their list of services and [examples](https://github.com/caronc/apprise#command-line-usage).
### Automatic login, two-factor authentication
If you set the options for email, password and OTP key, there will be no prompts and logins should happen automatically. This is optional since all stores should stay logged in since cookies are refreshed.
To get the OTP key, it is easiest to follow the store's guide for adding an authenticator app. You should also scan the shown QR code with your favorite app to have an alternative method for 2FA.
- **Epic Games**: visit [password & security](https://www.epicgames.com/account/password), enable 'third-party authenticator app', copy the 'Manual Entry Key' and use it to set `EG_OTPKEY`.
- **Prime Gaming**: visit Amazon 'Your Account Login & security', 2-step verification Manage Add new app Can't scan the barcode, copy the bold key and use it to set `PG_OTPKEY`
- **GOG**: only offers OTP via email
<!-- - **Xbox**: visit [additional security](https://account.live.com/proofs/manage/additional) > Add a new way to sign in or verify > Use an app > Set up a different Authenticator app > I can't scan the bar code > copy the bold key and use it to set `XBOX_OTPKEY` -->
Beware that storing passwords and OTP keys as clear text may be a security risk. Use a unique/generated password! TODO: maybe at least offer to base64 encode for storage.
### Epic Games Store
Run `node epic-games` (locally or in Docker).
### Amazon Prime Gaming
Run `node prime-gaming` (locally or in Docker).
Claiming the Amazon Games works out-of-the-box, however, for games on external stores you need to either link your account or redeem a key.
- Stores that require account linking: Epic Games, Battle.net, Origin.
- Stores that require redeeming a key: GOG.com, Microsoft Games, Legacy Games.
Keys and URLs are printed to the console, included in notifications and saved in `data/prime-gaming.json`. A screenshot of the page with the key is also saved to `data/screenshots`.
[TODO](https://github.com/vogler/free-games-claimer/issues/5): ~~redeem keys on external stores.~~
<!-- ### Xbox Games With Gold -->
<!-- Run `node xbox` (locally or in docker). -->
### Run periodically
#### How often?
Epic Games usually has two free games *every week*, before Christmas every day.
Prime Gaming has new games *every month* or more often during Prime days.
GOG usually has one new game every couples of weeks.
Unreal Engine has new assets to claim *every first Tuesday of a month*.
<!-- Xbox usually has two games *every month*. -->
It is safe to run the scripts every day.
#### How to schedule?
The container/scripts will claim currently available games and then exit.
If you want it to run regularly, you have to schedule the runs yourself:
- Linux/macOS: `crontab -e` ([example](https://github.com/vogler/free-games-claimer/discussions/56))
- macOS: [launchd](https://stackoverflow.com/questions/132955/how-do-i-set-a-task-to-run-every-so-often)
- Windows: [task scheduler](https://active-directory-wp.com/docs/Usage/How_to_add_a_cron_job_on_Windows/Scheduled_tasks_and_cron_jobs_on_Windows/index.html), [other options](https://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron)
- any OS: use a process manager like [pm2](https://pm2.keymetrics.io/docs/usage/restart-strategies/)
- Docker Compose `command: bash -c "node epic-games; node prime-gaming; node gog; echo sleeping; sleep 1d"` additionally add `restart: unless-stopped` to it.
TODO: ~~add some server-mode where the script just keeps running and claims games e.g. every day.~~
### Problems?
Check the open [issues](https://github.com/vogler/free-games-claimer/issues) and comment there or open a new issue.
If you're a developer, you can use `PWDEBUG=1 ...` to [inspect](https://playwright.dev/docs/inspector) which opens a debugger where you can step through the script.
## History/DevLog
<details>
<summary>Click to expand</summary>
Tried [epicgames-freebies-claimer](https://github.com/Revadike/epicgames-freebies-claimer), but had problems since epicgames introduced hcaptcha (see [issue](https://github.com/Revadike/epicgames-freebies-claimer/issues/172)).
Played around with puppeteer before, now trying newer https://playwright.dev which is pretty similar.
Playwright Inspector and `codegen` to generate scripts are nice, but failed to generate the right code for clicking a button in an iframe.
Added [main.spec.ts](https://github.com/vogler/epicgames-claimer/commit/e5ce7916ab6329cfc7134677c4d89c2b3fa3ba97#diff-d18d03e9c407a20e05fbf03cbd6f9299857740544fb6b50d6a70b9c6fbc35831) which was the test script generated by `npx playwright codegen` with manual fix for clicking buttons in the created iframe. Can be executed by `npx playwright test`. The test runner has options `--debug` and `--timeout` and can execute typescript which is nice. However, this only worked up to the button 'I Agree', and then showed an hcaptcha.
Added [main.captcha.js](https://github.com/vogler/epicgames-claimer/commit/e5ce7916ab6329cfc7134677c4d89c2b3fa3ba97#diff-d18d03e9c407a20e05fbf03cbd6f9299857740544fb6b50d6a70b9c6fbc35831) which uses beta of `playwright-extra@next` and `@extra/recaptcha@next` (from [comment on puppeteer-extra](https://github.com/berstend/puppeteer-extra/pull/303#issuecomment-775277480)).
However, `playwright-extra` seems to be old and missing `:has-text` selector (fixed [here](https://github.com/vogler/epicgames-claimer/commit/ba97a0e840b65f4476cca18e28d8461b0c703420)) and `page.frameLocator`, so the script did not run without adjustments.
Also, solving via [2captcha](https://2captcha.com?from=13225256) is a paid service which takes time and may be unreliable.
<!-- Alternative: https://anti-captcha.com -->
Added [main.stealth.js](https://github.com/vogler/epicgames-claimer/commit/64d0ba8ce71baec3947d1b64acd567befcb39340#diff-f70d3bd29df4a343f11062a97063953173491ce30fe34f69a0fc52517adbf342) which uses the stealth plugin without `playwright-extra` wrapper but up-to-date `playwright` (from [comment](https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212)).
The listed evasions are enough to not show an hcaptcha. Script claimed game successfully in non-headless mode.
Removed `main.captcha.js`.
Using Playwright Test (`main.spec.ts`) instead of Library (`main.stealth.js`) has the advantage of free CLI like `--debug` and `--timeout`.
<!-- TODO: check if stealth plugin can be setup with `contextOptions` ([doc](https://playwright.dev/docs/test-configuration#more-browser-and-context-options)). -->
Button selectors should preferably use text in order to be more stable against changes in the DOM.
Renamed repository from epicgames-claimer to free-games-claimer since a script for Amazon Prime Gaming was also added. Removed all old scripts in favor of just `epic-games.js` and `prime-gaming.js`.
epic games: `headless` mode gets hcaptcha challenge. More details/references in [issue](https://github.com/vogler/free-games-claimer/issues/2).
https://github.com/vogler/free-games-claimer/pull/11 introduced a Dockerfile for running non-headless inside the container via xvfb which makes it headless for the host running the container.
v1.0 Standalone scripts node epic-games and node prime-gaming using Chromium.
Changed to Firefox for all scripts since Chromium led to captchas. Claiming then also worked in headless mode without Docker.
Added options via env vars, configurable in `data/config.env`.
Added OTP generation via otplib for automatic login, even with 2FA.
Added notifications via [apprise](https://github.com/caronc/apprise).
</details>
[![Star History Chart](https://api.star-history.com/svg?repos=vogler/free-games-claimer&type=Date)](https://star-history.com/#vogler/free-games-claimer&Date)
---
Logo with smaller aspect ratio (for Telegram bot etc.): 👾 - [emojipedia](https://emojipedia.org/alien-monster/)
![logo-fgc](https://user-images.githubusercontent.com/493741/214589922-093d6557-6393-421c-b577-da58ff3671bc.png)

113
aliexpress.js Normal file
View file

@ -0,0 +1,113 @@
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
import { datetime, filenamify, prompt, handleSIGINT } from './src/util.js';
import { cfg } from './src/config.js';
// using https://github.com/apify/fingerprint-suite worked, but has no launchPersistentContext...
// from https://github.com/apify/fingerprint-suite/issues/162
import { FingerprintInjector } from 'fingerprint-injector';
import { FingerprintGenerator } from 'fingerprint-generator';
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
devices: ['mobile'],
operatingSystems: ['android'],
});
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless,
locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
recordHar: cfg.record ? { path: `data/record/aliexpress-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
userAgent: fingerprint.navigator.userAgent,
viewport: {
width: fingerprint.screen.width,
height: fingerprint.screen.height,
},
extraHTTPHeaders: {
'accept-language': headers['accept-language'],
},
});
handleSIGINT(context);
await new FingerprintInjector().attachFingerprintToPlaywright(context, { fingerprint, headers });
context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
const auth = async url => {
console.log('auth', url);
await page.goto(url, { waitUntil: 'domcontentloaded' });
// redirects to https://login.aliexpress.com/?return_url=https%3A%2F%2Fwww.aliexpress.com%2Fp%2Fcoin-pc-index%2Findex.html
await Promise.any([page.waitForURL(url => url.includes('login.aliexpress.com')).then(async () => {
console.error('Not logged in! Will wait for 120s for you to login...');
page.locator('span:has-text("Switch account")').click().catch(() => {}); // sometimes no longer logged in, but previous user/email is pre-selected -> in this case we want to go back to the classic login
const login = page.locator('.login-container');
const email = cfg.ae_email || await prompt({ message: 'Enter email' });
const emailInput = login.locator('input[label="Email or phone number"]');
await emailInput.fill(email);
await emailInput.blur(); // otherwise Continue button stays disabled
const continueButton = login.locator('button:has-text("Continue")');
await continueButton.click({ force: true }); // normal click waits for button to no longer be covered by their suggestion menu, so we have to force click somewhere for the menu to close and then click
await continueButton.click();
const password = email && (cfg.ae_password || await prompt({ type: 'password', message: 'Enter password' }));
await login.locator('input[label="Password"]').fill(password);
await login.locator('button:has-text("Sign in")').click();
const error = login.locator('.error-text');
error.waitFor().then(async () => console.error('Login error:', await error.innerText()));
await page.waitForURL(url);
page.getByRole('button', { name: 'Accept cookies' }).click().then(() => console.log('Accepted cookies')).catch(() => { });
}), page.locator('#nav-user-account').waitFor()]).catch(() => {});
};
// copied URLs from AliExpress app on tablet which has menu for the used webview
const urls = {
// works with desktop view, but stuck at 100% loading in mobile view:
coins: 'https://www.aliexpress.com/p/coin-pc-index/index.html',
// only work with mobile view:
grow: 'https://m.aliexpress.com/p/ae_fruit/index.html', // firefox: stuck at 60% loading, chrome: loads, but canvas
gogo: 'https://m.aliexpress.com/p/gogo-match-cc/index.html', // closes firefox?!
// only show notification to install the app
euro: 'https://m.aliexpress.com/p/european-cup/index.html', // doesn't load
merge: 'https://m.aliexpress.com/p/merge-market/index.html',
};
/* eslint-disable no-unused-vars */
const coins = async () => {
await Promise.any([page.locator('.checkin-button').click(), page.locator('.addcoin').waitFor()]);
console.log('Coins:', await page.locator('.mycoin-content-right-money').innerText());
console.log('Streak:', await page.locator('.title-box').innerText());
console.log('Tomorrow:', await page.locator('.addcoin').innerText());
};
const grow = async () => {
await page.pause();
};
const gogo = async () => {
await page.pause();
};
const euro = async () => {
await page.pause();
};
const merge = async () => {
await page.pause();
};
/* eslint-enable no-unused-vars */
try {
await [
merge,
].reduce((a, f) => a.then(async () => {
await auth(urls[f.name]);
await f();
console.log();
}), Promise.resolve());
} catch (error) {
process.exitCode ||= 1;
console.error('--- Exception:');
console.error(error); // .toString()?
}
if (page.video()) console.log('Recorded video:', await page.video().path());
await context.close();

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
set -eo pipefail # exit on error, error on any fail in pipe (not just last cmd); add -x to print each cmd; see gist bash_strict_mode.md set -eo pipefail # exit on error, error on any fail in pipe (not just last cmd); add -x to print each cmd; see gist bash_strict_mode.md
@ -6,23 +6,34 @@ echo "Version: https://github.com/vogler/free-games-claimer/tree/${COMMIT}"
[ ! -z $BRANCH ] && [ $BRANCH != "main" ] && echo "Branch: ${BRANCH}" [ ! -z $BRANCH ] && [ $BRANCH != "main" ] && echo "Branch: ${BRANCH}"
echo "Build: $NOW" echo "Build: $NOW"
# Ensure writable data dir for fgc when host bind-mount is owned by root.
if [ "$(id -u)" -eq 0 ]; then
chown -R 1000:1000 /fgc/data 2>/dev/null || true
fi
# Remove chromium profile lock. # Remove chromium profile lock.
# When running in docker and then killing it, on the next run chromium displayed a dialog to unlock the profile which made the script time out. # When running in docker and then killing it, on the next run chromium displayed a dialog to unlock the profile which made the script time out.
# Maybe due to changed hostname of container or due to how the docker container kills playwright - didn't check. # Maybe due to changed hostname of container or due to how the docker container kills playwright - didn't check.
# https://bugs.chromium.org/p/chromium/issues/detail?id=367048 # https://bugs.chromium.org/p/chromium/issues/detail?id=367048
rm -f /fgc/data/browser/SingletonLock rm -f /fgc/data/browser/SingletonLock 2>/dev/null || true
# Firefox preferences are stored in $BROWSER_DIR/pref.js and can be overridden by a file user.js # Firefox preferences are stored in $BROWSER_DIR/pref.js and can be overridden by a file user.js
# Since this file has to be in the volume (data/browser), we can't do this in Dockerfile. # Since this file has to be in the volume (data/browser), we can't do this in Dockerfile.
mkdir -p /fgc/data/browser mkdir -p /fgc/data/browser
# clean up stale firefox locks that can trigger "already running"
rm -f /fgc/data/browser/parent.lock /fgc/data/browser/lock /fgc/data/browser/.parentlock 2>/dev/null || true
# fix for 'Incorrect response' after solving a captcha correctly - https://github.com/vogler/free-games-claimer/issues/261#issuecomment-1868385830 # fix for 'Incorrect response' after solving a captcha correctly - https://github.com/vogler/free-games-claimer/issues/261#issuecomment-1868385830
# echo 'user_pref("privacy.resistFingerprinting", true);' > /fgc/data/browser/user.js # Only write the prefs file when the volume is writable (container runs as non-root).
cat << EOT > /fgc/data/browser/user.js if [ -w /fgc/data/browser ] && { [ ! -e /fgc/data/browser/user.js ] || [ -w /fgc/data/browser/user.js ] || rm -f /fgc/data/browser/user.js 2>/dev/null; }; then
cat << 'EOT' > /fgc/data/browser/user.js
user_pref("privacy.resistFingerprinting", true); user_pref("privacy.resistFingerprinting", true);
// user_pref("privacy.resistFingerprinting.letterboxing", true); // user_pref("privacy.resistFingerprinting.letterboxing", true);
// user_pref("browser.contentblocking.category", "strict"); // user_pref("browser.contentblocking.category", "strict");
// user_pref("webgl.disabled", true); // user_pref("webgl.disabled", true);
EOT EOT
else
echo "Warning: /fgc/data/browser not writable; skipping user.js creation."
fi
# TODO disable session restore message? # TODO disable session restore message?
# Remove X server display lock, fix for `docker compose up` which reuses container which made it fail after initial run, https://github.com/vogler/free-games-claimer/issues/31 # Remove X server display lock, fix for `docker compose up` which reuses container which made it fail after initial run, https://github.com/vogler/free-games-claimer/issues/31
@ -30,6 +41,12 @@ EOT
# ls -l /tmp/.X11-unix/ # ls -l /tmp/.X11-unix/
rm -f /tmp/.X1-lock rm -f /tmp/.X1-lock
# Ensure X11 socket dir exists with sane ownership/permissions.
mkdir -p /tmp/.X11-unix
if [ "$(stat -c %U /tmp/.X11-unix 2>/dev/null)" != "root" ]; then
chown root:root /tmp/.X11-unix 2>/dev/null || chmod 1777 /tmp/.X11-unix
fi
# 6000+SERVERNUM is the TCP port Xvfb is listening on: # 6000+SERVERNUM is the TCP port Xvfb is listening on:
# SERVERNUM=$(echo "$DISPLAY" | sed 's/:\([0-9][0-9]*\).*/\1/') # SERVERNUM=$(echo "$DISPLAY" | sed 's/:\([0-9][0-9]*\).*/\1/')
@ -52,4 +69,11 @@ echo "VNC is running on port $VNC_PORT ($pwt)"
websockify -D --web "/usr/share/novnc/" $NOVNC_PORT "localhost:$VNC_PORT" 2>/dev/null 1>&2 & websockify -D --web "/usr/share/novnc/" $NOVNC_PORT "localhost:$VNC_PORT" 2>/dev/null 1>&2 &
echo "noVNC (VNC via browser) is running on http://localhost:$NOVNC_PORT" echo "noVNC (VNC via browser) is running on http://localhost:$NOVNC_PORT"
echo echo
# Ensure Playwright browsers are available (chromium + firefox).
if [ ! -x /home/fgc/.cache/ms-playwright/firefox-1482/firefox/firefox ] || ! ls /home/fgc/.cache/ms-playwright/chromium-*/*/chrome >/dev/null 2>&1; then
echo "Playwright browsers missing; installing..."
npx playwright install chromium firefox || echo "Warning: failed to install Playwright browsers" >&2
fi
exec tini -g -- "$@" # https://github.com/krallin/tini/issues/8 node/playwright respond to signals like ctrl-c, but unsure about zombie processes exec tini -g -- "$@" # https://github.com/krallin/tini/issues/8 node/playwright respond to signals like ctrl-c, but unsure about zombie processes

View file

@ -1,7 +1,8 @@
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
import { authenticator } from 'otplib'; import { authenticator } from 'otplib';
import path from 'path'; import chalk from 'chalk';
import { existsSync, writeFileSync } from 'fs'; import path from 'node:path';
import { existsSync, writeFileSync, appendFileSync } from 'node:fs';
import { resolve, jsonDb, datetime, stealth, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js'; import { resolve, jsonDb, datetime, stealth, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js';
import { cfg } from './src/config.js'; import { cfg } from './src/config.js';
@ -16,21 +17,25 @@ const db = await jsonDb('epic-games.json', {});
if (cfg.time) console.time('startup'); if (cfg.time) console.time('startup');
const browserPrefs = path.join(cfg.dir.browser, 'prefs.js');
if (existsSync(browserPrefs)) {
console.log('Adding webgl.disabled to', browserPrefs);
appendFileSync(browserPrefs, 'user_pref("webgl.disabled", true);'); // apparently Firefox removes duplicates (and sorts), so no problem appending every time
} else {
console.log(browserPrefs, 'does not exist yet, will patch it on next run. Restart the script if you get a captcha.');
}
// https://playwright.dev/docs/auth#multi-factor-authentication // https://playwright.dev/docs/auth#multi-factor-authentication
const context = await firefox.launchPersistentContext(cfg.dir.browser, { const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless, headless: cfg.headless,
viewport: { width: cfg.width, height: cfg.height }, viewport: { width: cfg.width, height: cfg.height },
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36', // see replace of Headless in util.newStealthContext. TODO Windows UA enough to avoid 'device not supported'? update if browser is updated? userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0', // Windows UA avoids "device not supported"; update when browser version changes
// userAgent firefox (macOS): Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0
// userAgent firefox (docker): Mozilla/5.0 (X11; Linux aarch64; rv:109.0) Gecko/20100101 Firefox/115.0
locale: 'en-US', // ignore OS locale to be sure to have english text for locators locale: 'en-US', // ignore OS locale to be sure to have english text for locators
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800 recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
recordHar: cfg.record ? { path: `data/record/eg-${datetime()}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools recordHar: cfg.record ? { path: `data/record/eg-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
// user settings for firefox have to be put in $BROWSER_DIR/user.js // user settings for firefox have to be put in $BROWSER_DIR/user.js
args: [ // https://wiki.mozilla.org/Firefox/CommandLineOptions args: [], // https://wiki.mozilla.org/Firefox/CommandLineOptions
// '-kiosk',
],
}); });
handleSIGINT(context); handleSIGINT(context);
@ -41,8 +46,20 @@ await stealth(context);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
// eslint-disable-next-line no-undef await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaround for https://github.com/vogler/free-games-claimer/issues/277 until Playwright fixes it
if (cfg.debug) console.debug(await page.evaluate(() => [window.screen, navigator.userAgent, navigator.platform]));
// some debug info about the page (screen dimensions, user agent)
if (cfg.debug) {
/* global window, navigator */
const debugInfo = await page.evaluate(() => {
const { width, height, availWidth, availHeight } = window.screen;
return {
screen: { width, height, availWidth, availHeight },
userAgent: navigator.userAgent,
};
});
console.debug(debugInfo);
}
if (cfg.debug_network) { if (cfg.debug_network) {
// const filter = _ => true; // const filter = _ => true;
const filter = r => r.url().includes('store.epicgames.com'); const filter = r => r.url().includes('store.epicgames.com');
@ -64,8 +81,6 @@ try {
if (cfg.time) console.timeEnd('startup'); if (cfg.time) console.timeEnd('startup');
if (cfg.time) console.time('login'); if (cfg.time) console.time('login');
// page.click('button:has-text("Accept All Cookies")').catch(_ => { }); // Not needed anymore since we set the cookie above. Clicking this did not always work since the message was animated in too slowly.
while (await page.locator('egs-navigation').getAttribute('isloggedin') != 'true') { while (await page.locator('egs-navigation').getAttribute('isloggedin') != 'true') {
console.error('Not signed in anymore. Please login in the browser or here in the terminal.'); console.error('Not signed in anymore. Please login in the browser or here in the terminal.');
if (cfg.novnc_port) console.info(`Open http://localhost:${cfg.novnc_port} to login inside the docker container.`); if (cfg.novnc_port) console.info(`Open http://localhost:${cfg.novnc_port} to login inside the docker container.`);
@ -84,31 +99,56 @@ try {
} }
}; };
const email = cfg.eg_email || await prompt({ message: 'Enter email' }); const email = cfg.eg_email || await prompt({ message: 'Enter email' });
if (!email) await notifyBrowserLogin(); if (email) {
else { const watchCaptchaChallenge = async () => {
// await page.click('text=Sign in with Epic Games'); try {
await page.fill('#email', email); await page.waitForSelector('.h_captcha_challenge iframe', { timeout: 15000 });
await page.click('button[type="submit"]');
page.waitForSelector('.h_captcha_challenge iframe').then(async () => {
console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.'); console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.');
await notify('epic-games: got captcha during login. Please check.'); await notify('epic-games: got captcha during login. Please check.');
}).catch(_ => { }); } catch {
page.waitForSelector('p:has-text("Incorrect response.")').then(async () => { return;
console.error('Incorrect repsonse for captcha!'); }
}).catch(_ => { }); };
const password = email && (cfg.eg_password || await prompt({ type: 'password', message: 'Enter password' })); const watchCaptchaIncorrect = async () => {
if (!password) await notifyBrowserLogin(); try {
await page.waitForSelector('p:has-text("Incorrect response.")', { timeout: 15000 });
console.error('Incorrect response for captcha!');
} catch {
return;
}
};
watchCaptchaChallenge();
watchCaptchaIncorrect();
await page.fill('#email', email);
const password = cfg.eg_password || await prompt({ type: 'password', message: 'Enter password' });
if (password) {
await page.fill('#password', password); await page.fill('#password', password);
await page.click('button[type="submit"]'); await page.click('button[type="submit"]');
// handle MFA, but don't await it } else await notifyBrowserLogin();
page.waitForURL('**/id/login/mfa**').then(async () => { const error = page.locator('#form-error-message');
const watchLoginError = async () => {
try {
await error.waitFor({ timeout: 15000 });
console.error('Login error:', await error.innerText());
console.log('Please login in the browser!');
} catch {
return;
}
};
const watchMfaStep = async () => {
try {
await page.waitForURL('**/id/login/mfa**', { timeout: cfg.login_timeout });
console.log('Enter the security code to continue - This appears to be a new device, browser or location. A security code has been sent to your email address at ...'); console.log('Enter the security code to continue - This appears to be a new device, browser or location. A security code has been sent to your email address at ...');
// TODO locator for text (email or app?)
const otp = cfg.eg_otpkey && authenticator.generate(cfg.eg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them const otp = cfg.eg_otpkey && authenticator.generate(cfg.eg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
await page.locator('input[name="code-input-0"]').pressSequentially(otp.toString()); await page.locator('input[name="code-input-0"]').pressSequentially(otp.toString());
await page.click('button[type="submit"]'); await page.click('button[type="submit"]');
}).catch(_ => { }); } catch {
return;
} }
};
watchLoginError();
watchMfaStep();
} else await notifyBrowserLogin();
await page.waitForURL(URL_CLAIM); await page.waitForURL(URL_CLAIM);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
} }
@ -122,7 +162,7 @@ try {
const game_loc = page.locator('a:has(span:text-is("Free Now"))'); const game_loc = page.locator('a:has(span:text-is("Free Now"))');
await game_loc.last().waitFor().catch(_ => { await game_loc.last().waitFor().catch(_ => {
// rarely there are no free games available -> catch Timeout // rarely there are no free games available -> catch Timeout
// TODO would be better to wait for alternative like 'coming soon' instead of waiting for timeout // waiting for timeout; alternative would be waiting for "coming soon"
// see https://github.com/vogler/free-games-claimer/issues/210#issuecomment-1727420943 // see https://github.com/vogler/free-games-claimer/issues/210#issuecomment-1727420943
console.error('Seems like currently there are no free games available in your region...'); console.error('Seems like currently there are no free games available in your region...');
// urls below should then be an empty list // urls below should then be an empty list
@ -138,59 +178,84 @@ try {
for (const url of urls) { for (const url of urls) {
if (cfg.time) console.time('claim game'); if (cfg.time) console.time('claim game');
await page.goto(url); // , { waitUntil: 'domcontentloaded' }); await page.goto(url); // , { waitUntil: 'domcontentloaded' });
const btnText = await page.locator('//button[@data-testid="purchase-cta-button"][not(contains(.,"Loading"))]').first().innerText(); // barrier to block until page is loaded const purchaseBtn = page.locator('button[data-testid="purchase-cta-button"] >> :has-text("e"), :has-text("i")').first(); // when loading, the button text is empty -> need to wait for some text {'get', 'in library', 'requires base game'} -> just wait for e or i to not be too specific; :text-matches("\w+") somehow didn't work - https://github.com/vogler/free-games-claimer/issues/375
await purchaseBtn.waitFor();
const btnText = (await purchaseBtn.innerText()).toLowerCase(); // barrier to block until page is loaded
// click Continue if 'This game contains mature content recommended only for ages 18+' // click Continue if 'This game contains mature content recommended only for ages 18+'
if (await page.locator('button:has-text("Continue")').count() > 0) { if (await page.locator('button:has-text("Continue")').count() > 0) {
console.log(' This game contains mature content recommended only for ages 18+'); console.log(' This game contains mature content recommended only for ages 18+');
if (await page.locator('[data-testid="AgeSelect"]').count()) { if (await page.locator('[data-testid="AgeSelect"]').count()) {
console.error(' Got "To continue, please provide your date of birth" - This shouldn\'t happen due to cookie set above. Please report to https://github.com/vogler/free-games-claimer/issues/275'); console.error(' Got "To continue, please provide your date of birth" - This shouldn\'t happen due to cookie set above. Please report to https://github.com/vogler/free-games-claimer/issues/275');
await page.locator('#month_toggle').click();
await page.locator('#month_menu li:has-text("01")').click();
await page.locator('#day_toggle').click();
await page.locator('#day_menu li:has-text("01")').click();
await page.locator('#year_toggle').click();
await page.locator('#year_menu li:has-text("1987")').click();
} }
await page.click('button:has-text("Continue")', { delay: 111 }); await page.click('button:has-text("Continue")', { delay: 111 });
await page.waitForTimeout(2000); await page.waitForTimeout(2000);
} }
const title = await page.locator('h1').first().innerText(); let title;
let bundle_includes;
if (await page.locator('span:text-is("About Bundle")').count()) {
title = (await page.locator('span:has-text("Buy"):left-of([data-testid="purchase-cta-button"])').first().innerText()).replace('Buy ', '');
// h1 first didn't exist for bundles but now it does... However h1 would e.g. be 'Fallout® Classic Collection' instead of 'Fallout Classic Collection'
try {
bundle_includes = await Promise.all((await page.locator('.product-card-top-row h5').all()).map(b => b.innerText()));
} catch (e) {
console.error('Failed to get "Bundle Includes":', e);
}
} else {
title = await page.locator('h1').first().innerText();
}
const game_id = page.url().split('/').pop(); const game_id = page.url().split('/').pop();
const existedInDb = db.data[user][game_id];
db.data[user][game_id] ||= { title, time: datetime(), url: page.url() }; // this will be set on the initial run only! db.data[user][game_id] ||= { title, time: datetime(), url: page.url() }; // this will be set on the initial run only!
console.log('Current free game:', title); console.log('Current free game:', chalk.blue(title));
if (bundle_includes) console.log(' This bundle includes:', bundle_includes);
const notify_game = { title, url, status: 'failed' }; const notify_game = { title, url, status: 'failed' };
notify_games.push(notify_game); // status is updated below notify_games.push(notify_game); // status is updated below
if (btnText.toLowerCase() == 'in library') { if (btnText == 'in library') {
console.log(' Already in library! Nothing to claim.'); console.log(' Already in library! Nothing to claim.');
if (!existedInDb) await notify(`Game already in library: ${url}`);
notify_game.status = 'existed'; notify_game.status = 'existed';
db.data[user][game_id].status ||= 'existed'; // does not overwrite claimed or failed db.data[user][game_id].status ||= 'existed'; // does not overwrite claimed or failed
if (db.data[user][game_id].status.startsWith('failed')) db.data[user][game_id].status = 'manual'; // was failed but now it's claimed if (db.data[user][game_id].status.startsWith('failed')) db.data[user][game_id].status = 'manual'; // was failed but now it's claimed
} else if (btnText.toLowerCase() == 'requires base game') { } else if (btnText == 'requires base game') {
console.log(' Requires base game! Nothing to claim.'); console.log(' Requires base game! Nothing to claim.');
notify_game.status = 'requires base game'; notify_game.status = 'requires base game';
db.data[user][game_id].status ||= 'failed:requires-base-game'; db.data[user][game_id].status ||= 'failed:requires-base-game';
// TODO claim base game if it is free // if base game is free, add to queue as well
const baseUrl = 'https://store.epicgames.com' + await page.locator('a:has-text("Overview")').getAttribute('href'); const baseUrl = 'https://store.epicgames.com' + await page.locator('a:has-text("Overview")').getAttribute('href');
console.log(' Base game:', baseUrl); console.log(' Base game:', baseUrl);
// await page.click('a:has-text("Overview")'); // await page.click('a:has-text("Overview")');
// re-add original add-on to queue after base game
urls.push(baseUrl, url); // add base game to the list of games to claim and re-add add-on itself
} else { // GET } else { // GET
console.log(' Not in library yet! Click GET.'); console.log(' Not in library yet! Click', btnText);
await page.click('[data-testid="purchase-cta-button"]', { delay: 11 }); // got stuck here without delay (or mouse move), see #75, 1ms was also enough await purchaseBtn.click({ delay: 11 }); // got stuck here without delay (or mouse move), see #75, 1ms was also enough
// click Continue if 'Device not supported. This product is not compatible with your current device.' - avoided by Windows userAgent?
page.click('button:has-text("Continue")').catch(_ => { }); // needed since change from Chromium to Firefox?
// click 'Yes, buy now' if 'This edition contains something you already have. Still interested?'
page.click('button:has-text("Yes, buy now")').catch(_ => { });
// Accept End User License Agreement (only needed once) // Accept End User License Agreement (only needed once)
page.locator('input#agree').waitFor().then(async () => { const acceptEulaIfShown = async () => {
console.log('Accept End User License Agreement (only needed once)'); try {
await page.locator(':has-text("end user license agreement")').waitFor({ timeout: 10000 });
console.log(' Accept End User License Agreement (only needed once)');
await page.locator('input#agree').check(); await page.locator('input#agree').check();
await page.locator('button:has-text("Accept")').click(); await page.locator('button:has-text("Accept")').click();
}).catch(_ => { }); } catch {
return;
}
};
acceptEulaIfShown();
// it then creates an iframe for the purchase // it then creates an iframe for the purchase
await page.waitForSelector('#webPurchaseContainer iframe'); // TODO needed? await page.waitForSelector('#webPurchaseContainer iframe');
const iframe = page.frameLocator('#webPurchaseContainer iframe'); const iframe = page.frameLocator('#webPurchaseContainer iframe');
// skip game if unavailable in region, https://github.com/vogler/free-games-claimer/issues/46 TODO check games for account's region // skip game if unavailable in region, https://github.com/vogler/free-games-claimer/issues/46
if (await iframe.locator(':has-text("unavailable in your region")').count() > 0) { if (await iframe.locator(':has-text("unavailable in your region")').count() > 0) {
console.error(' This product is unavailable in your region!'); console.error(' This product is unavailable in your region!');
db.data[user][game_id].status = notify_game.status = 'unavailable-in-region'; db.data[user][game_id].status = notify_game.status = 'unavailable-in-region';
@ -198,14 +263,20 @@ try {
continue; continue;
} }
iframe.locator('.payment-pin-code').waitFor().then(async () => { const enterParentalPinIfNeeded = async () => {
try {
await iframe.locator('.payment-pin-code').waitFor({ timeout: 10000 });
if (!cfg.eg_parentalpin) { if (!cfg.eg_parentalpin) {
console.error(' EG_PARENTALPIN not set. Need to enter Parental Control PIN manually.'); console.error(' EG_PARENTALPIN not set. Need to enter Parental Control PIN manually.');
notify('epic-games: EG_PARENTALPIN not set. Need to enter Parental Control PIN manually.'); notify('epic-games: EG_PARENTALPIN not set. Need to enter Parental Control PIN manually.');
} }
await iframe.locator('input.payment-pin-code__input').first().pressSequentially(cfg.eg_parentalpin); await iframe.locator('input.payment-pin-code__input').first().pressSequentially(cfg.eg_parentalpin);
await iframe.locator('button:has-text("Continue")').click({ delay: 11 }); await iframe.locator('button:has-text("Continue")').click({ delay: 11 });
}).catch(_ => { }); } catch {
return;
}
};
enterParentalPinIfNeeded();
if (cfg.debug) await page.pause(); if (cfg.debug) await page.pause();
if (cfg.dryrun) { if (cfg.dryrun) {
@ -219,21 +290,39 @@ try {
await iframe.locator('button:has-text("Place Order"):not(:has(.payment-loading--loading))').click({ delay: 11 }); await iframe.locator('button:has-text("Place Order"):not(:has(.payment-loading--loading))').click({ delay: 11 });
// I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872 // I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872
const btnAgree = iframe.locator('button:has-text("I Agree")'); const btnAgree = iframe.locator('button:has-text("I Accept")');
btnAgree.waitFor().then(() => btnAgree.click()).catch(_ => { }); // EU: wait for and click 'I Agree' const acceptIfRequired = async () => {
try {
await btnAgree.waitFor({ timeout: 10000 });
await btnAgree.click();
} catch {
return;
}
}; // EU: wait for and click 'I Agree'
acceptIfRequired();
try { try {
// context.setDefaultTimeout(100 * 1000); // give time to solve captcha, iframe goes blank after 60s? // context.setDefaultTimeout(100 * 1000); // give time to solve captcha, iframe goes blank after 60s?
const captcha = iframe.locator('#h_captcha_challenge_checkout_free_prod iframe'); const captcha = iframe.locator('#h_captcha_challenge_checkout_free_prod iframe');
captcha.waitFor().then(async () => { // don't await, since element may not be shown const watchCaptchaChallenge = async () => {
// console.info(' Got hcaptcha challenge! NopeCHA extension will likely solve it.') try {
await captcha.waitFor({ timeout: 10000 });
console.error(' Got hcaptcha challenge! Lost trust due to too many login attempts? You can solve the captcha in the browser or get a new IP address.'); console.error(' Got hcaptcha challenge! Lost trust due to too many login attempts? You can solve the captcha in the browser or get a new IP address.');
await notify(`epic-games: got captcha challenge right before claim of <a href="${url}">${title}</a>. Use VNC to solve it manually.`); // TODO could even create purchase URL, see https://github.com/vogler/free-games-claimer/pull/130 await notify(`epic-games: got captcha challenge for.\nGame link: ${url}`);
// await page.waitForTimeout(2000); } catch {
// const p = path.resolve(cfg.dir.screenshots, 'epic-games', 'captcha', `${filenamify(datetime())}.png`); return;
// await captcha.screenshot({ path: p }); }
// console.info(' Saved a screenshot of hcaptcha challenge to', p); }; // may time out if not shown
// console.error(' Got hcaptcha challenge. To avoid it, get a link from https://www.hcaptcha.com/accessibility'); // TODO save this link in config and visit it daily to set accessibility cookie to avoid captcha challenge? const watchCaptchaFailure = async () => {
}).catch(_ => { }); // may time out if not shown try {
await iframe.locator('.payment__errors:has-text("Failed to challenge captcha, please try again later.")').waitFor({ timeout: 10000 });
console.error(' Failed to challenge captcha, please try again later.');
await notify('epic-games: failed to challenge captcha. Please check.');
} catch {
return;
}
};
watchCaptchaChallenge();
watchCaptchaFailure();
await page.locator('text=Thanks for your order!').waitFor({ state: 'attached' }); await page.locator('text=Thanks for your order!').waitFor({ state: 'attached' });
db.data[user][game_id].status = 'claimed'; db.data[user][game_id].status = 'claimed';
db.data[user][game_id].time = datetime(); // claimed time overwrites failed/dryrun time db.data[user][game_id].time = datetime(); // claimed time overwrites failed/dryrun time

View file

@ -11,7 +11,7 @@ export default [
{ {
ignores: ['data/**'], ignores: ['data/**'],
}, },
js.configs.recommended, // TODO still needed? js.configs.recommended,
{ {
// files: ['*.js'], // files: ['*.js'],
languageOptions: { languageOptions: {
@ -24,6 +24,7 @@ export default [
// https://eslint.style/packages/js // https://eslint.style/packages/js
rules: { rules: {
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'prefer-const': 'error',
'@stylistic/js/array-bracket-newline': ['error', 'consistent'], '@stylistic/js/array-bracket-newline': ['error', 'consistent'],
'@stylistic/js/array-bracket-spacing': 'error', '@stylistic/js/array-bracket-spacing': 'error',
'@stylistic/js/array-element-newline': ['error', 'consistent'], '@stylistic/js/array-element-newline': ['error', 'consistent'],

56
gog.js
View file

@ -1,4 +1,5 @@
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
import chalk from 'chalk';
import { resolve, jsonDb, datetime, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js'; import { resolve, jsonDb, datetime, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js';
import { cfg } from './src/config.js'; import { cfg } from './src/config.js';
@ -10,13 +11,18 @@ console.log(datetime(), 'started checking gog');
const db = await jsonDb('gog.json', {}); const db = await jsonDb('gog.json', {});
if (cfg.width < 1280) { // otherwise 'Sign in' and #menuUsername are hidden (but attached to DOM), see https://github.com/vogler/free-games-claimer/issues/335
console.error(`Window width is set to ${cfg.width} but needs to be at least 1280 for GOG!`);
process.exit(1);
}
// https://playwright.dev/docs/auth#multi-factor-authentication // https://playwright.dev/docs/auth#multi-factor-authentication
const context = await firefox.launchPersistentContext(cfg.dir.browser, { const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless, headless: cfg.headless,
viewport: { width: cfg.width, height: cfg.height }, viewport: { width: cfg.width, height: cfg.height },
locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800 recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
recordHar: cfg.record ? { path: `data/record/gog-${datetime()}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools recordHar: cfg.record ? { path: `data/record/gog-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
}); });
@ -25,7 +31,7 @@ handleSIGINT(context);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
// console.debug('userAgent:', await page.evaluate(() => navigator.userAgent)); await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaround for https://github.com/vogler/free-games-claimer/issues/277 until Playwright fixes it
const notify_games = []; const notify_games = [];
let user; let user;
@ -35,14 +41,13 @@ try {
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever
// page.click('#CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll').catch(_ => { }); // does not work reliably, solved by setting CookieConsent above
const signIn = page.locator('a:has-text("Sign in")').first(); const signIn = page.locator('a:has-text("Sign in")').first();
await Promise.any([signIn.waitFor(), page.waitForSelector('#menuUsername')]); await Promise.any([signIn.waitFor(), page.waitForSelector('#menuUsername')]);
while (await signIn.isVisible()) { while (await signIn.isVisible()) {
console.error('Not signed in anymore.'); console.error('Not signed in anymore.');
await signIn.click(); await signIn.click();
// it then creates an iframe for the login // it then creates an iframe for the login
await page.waitForSelector('#GalaxyAccountsFrameContainer iframe'); // TODO needed? await page.waitForSelector('#GalaxyAccountsFrameContainer iframe');
const iframe = page.frameLocator('#GalaxyAccountsFrameContainer iframe'); const iframe = page.frameLocator('#GalaxyAccountsFrameContainer iframe');
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in
console.info(`Login timeout is ${cfg.login_timeout / 1000} seconds!`); console.info(`Login timeout is ${cfg.login_timeout / 1000} seconds!`);
@ -55,22 +60,30 @@ try {
await iframe.locator('#login_username').fill(email); await iframe.locator('#login_username').fill(email);
await iframe.locator('#login_password').fill(password); await iframe.locator('#login_password').fill(password);
await iframe.locator('#login_login').click(); await iframe.locator('#login_login').click();
// handle MFA, but don't await it const handleTwoFactor = async () => {
iframe.locator('form[name=second_step_authentication]').waitFor().then(async () => { try {
await iframe.locator('form[name=second_step_authentication]').waitFor({ timeout: 15000 });
console.log('Two-Step Verification - Enter security code'); console.log('Two-Step Verification - Enter security code');
console.log(await iframe.locator('.form__description').innerText()); console.log(await iframe.locator('.form__description').innerText());
const otp = await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 4 || 'The code must be 4 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them const otp = await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 4 || 'The code must be 4 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
await iframe.locator('#second_step_authentication_token_letter_1').pressSequentially(otp.toString(), { delay: 10 }); await iframe.locator('#second_step_authentication_token_letter_1').pressSequentially(otp.toString(), { delay: 10 });
await iframe.locator('#second_step_authentication_send').click(); await iframe.locator('#second_step_authentication_send').click();
await page.waitForTimeout(1000); // TODO still needed with wait for username below? await page.waitForTimeout(1000);
}).catch(_ => { }); } catch {
// iframe.locator('iframe[title=reCAPTCHA]').waitFor().then(() => { return;
// iframe.locator('.g-recaptcha').waitFor().then(() => { }
iframe.locator('text=Invalid captcha').waitFor().then(() => { };
const watchInvalidCaptcha = async () => {
try {
await iframe.locator('text=Invalid captcha').waitFor({ timeout: 15000 });
console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.'); console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.');
notify('gog: got captcha during login. Please check.'); notify('gog: got captcha during login. Please check.');
// TODO solve reCAPTCHA? } catch {
}).catch(_ => { }); return;
}
};
handleTwoFactor();
watchInvalidCaptcha();
await page.waitForSelector('#menuUsername'); await page.waitForSelector('#menuUsername');
} else { } else {
console.log('Waiting for you to login in the browser.'); console.log('Waiting for you to login in the browser.');
@ -89,21 +102,20 @@ try {
db.data[user] ||= {}; db.data[user] ||= {};
const banner = page.locator('#giveaway'); const banner = page.locator('#giveaway');
if (!await banner.count()) { const hasGiveaway = await banner.count();
if (!hasGiveaway) {
console.log('Currently no free giveaway!'); console.log('Currently no free giveaway!');
} else { } else {
const text = await page.locator('.giveaway-banner__title').innerText(); const text = await page.locator('.giveaway__content-header').innerText();
const title = text.match(/Claim (.*)/)[1]; const match_all = text.match(/Claim (.*) and don't miss the|Success! (.*) was added to/);
const slug = await banner.getAttribute('href'); const title = match_all[1] ? match_all[1] : match_all[2];
const url = `https://gog.com${slug}`; const url = await banner.locator('a').first().getAttribute('href');
console.log(`Current free game: ${title} - ${url}`); console.log(`Current free game: ${chalk.blue(title)} - ${url}`);
db.data[user][title] ||= { title, time: datetime(), url }; db.data[user][title] ||= { title, time: datetime(), url };
if (cfg.dryrun) process.exit(1); if (cfg.dryrun) process.exit(1);
// await page.locator('#giveaway:not(.is-loading)').waitFor(); // otherwise screenshot is sometimes with loading indicator instead of game title; #TODO fix, skipped due to timeout, see #240
await banner.screenshot({ path: screenshot(`${filenamify(title)}.png`) }); // overwrites every time - only keep first? await banner.screenshot({ path: screenshot(`${filenamify(title)}.png`) }); // overwrites every time - only keep first?
// await banner.getByRole('button', { name: 'Add to library' }).click(); // instead of clicking the button, visit the auto-claim URL which gives a JSON response
// instead of clicking the button, we visit the auto-claim URL which gives as a JSON response which is easier than checking the state of a button
await page.goto('https://www.gog.com/giveaway/claim'); await page.goto('https://www.gog.com/giveaway/claim');
const response = await page.innerText('body'); const response = await page.innerText('body');
// console.log(response); // console.log(response);

2949
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -17,20 +17,21 @@
}, },
"type": "module", "type": "module",
"engines": { "engines": {
"node": ">=15" "node": ">=17"
}, },
"dependencies": { "dependencies": {
"chalk": "^5.3.0", "chalk": "^5.4.1",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dotenv": "^16.3.1", "dotenv": "^16.5.0",
"enquirer": "^2.4.1", "enquirer": "^2.4.1",
"lowdb": "^6.1.1", "fingerprint-injector": "^2.1.66",
"lowdb": "^7.0.1",
"otplib": "^12.0.1", "otplib": "^12.0.1",
"playwright-firefox": "^1.40.1", "playwright-firefox": "^1.52.0",
"puppeteer-extra-plugin-stealth": "^2.11.2" "puppeteer-extra-plugin-stealth": "^2.11.2"
}, },
"devDependencies": { "devDependencies": {
"@stylistic/eslint-plugin-js": "^1.5.1", "@stylistic/eslint-plugin-js": "^4.2.0",
"eslint": "^8.56.0" "eslint": "^9.26.0"
} }
} }

View file

@ -6,8 +6,7 @@ import { cfg } from './src/config.js';
const screenshot = (...a) => resolve(cfg.dir.screenshots, 'prime-gaming', ...a); const screenshot = (...a) => resolve(cfg.dir.screenshots, 'prime-gaming', ...a);
// const URL_LOGIN = 'https://www.amazon.de/ap/signin'; // wrong. needs some session args to be valid? const URL_CLAIM = 'https://luna.amazon.com/claims/home';
const URL_CLAIM = 'https://gaming.amazon.com/home';
console.log(datetime(), 'started checking prime-gaming'); console.log(datetime(), 'started checking prime-gaming');
@ -19,29 +18,86 @@ const context = await firefox.launchPersistentContext(cfg.dir.browser, {
viewport: { width: cfg.width, height: cfg.height }, viewport: { width: cfg.width, height: cfg.height },
locale: 'en-US', // ignore OS locale to be sure to have english text for locators locale: 'en-US', // ignore OS locale to be sure to have english text for locators
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800 recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
recordHar: cfg.record ? { path: `data/record/pg-${datetime()}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools recordHar: cfg.record ? { path: `data/record/pg-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
}); });
handleSIGINT(context); handleSIGINT(context);
// TODO test if needed
await stealth(context); await stealth(context);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
// console.debug('userAgent:', await page.evaluate(() => navigator.userAgent)); await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaround for https://github.com/vogler/free-games-claimer/issues/277 until Playwright fixes it
const notify_games = []; const notify_games = [];
let user; let user;
const handleMFA = async p => {
const otpField = p.locator('#auth-mfa-otpcode, input[name=otpCode]');
if (!await otpField.count()) return false;
console.log('Two-Step Verification - enter the One Time Password (OTP), e.g. generated by your Authenticator App');
await p.locator('#auth-mfa-remember-device, [name=rememberDevice]').check().catch(() => {});
const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
await otpField.first().pressSequentially(otp.toString());
await p.locator('input[type="submit"], button[type="submit"]').first().click();
return true;
};
try { try {
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever
const handleDirectLoginPage = async () => {
if (!page.url().includes('/ap/signin')) return false;
console.log('On Amazon login page (redirect). Trying to sign in automatically.');
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout);
const email = cfg.pg_email || await prompt({ message: 'Enter email' });
const password = email && (cfg.pg_password || await prompt({ type: 'password', message: 'Enter password' }));
if (email && password) {
await page.fill('[name=email]', email);
await page.click('input[type="submit"]');
await page.fill('[name=password]', password);
await page.click('input[type="submit"]');
await handleMFA(page).catch(() => {});
try {
await page.waitForURL('**/ap/signin**');
const error = await page.locator('.a-alert-content').first().innerText();
if (error.trim().length) {
console.error('Login error:', error);
await notify(`prime-gaming: login: ${error}`);
await context.close(); // finishes potential recording
process.exit(1);
}
} catch {
// if navigation succeeded, continue
}
await page.waitForURL(/luna\.amazon\.com\/claims\/.*signedIn=true/);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
return true;
} else {
console.log('Waiting for manual login on redirect page.');
if (cfg.headless) {
console.log('Run `SHOW=1 node prime-gaming` to login in the opened browser.');
await context.close(); // finishes potential recording
process.exit(1);
}
return true;
}
};
await handleDirectLoginPage();
// need to wait for some elements to exist before checking if signed in or accepting cookies: // need to wait for some elements to exist before checking if signed in or accepting cookies:
await Promise.any(['button:has-text("Sign in")', '[data-a-target="user-dropdown-first-name-text"]'].map(s => page.waitForSelector(s))); await Promise.any([
page.click('[aria-label="Cookies usage disclaimer banner"] button:has-text("Accept Cookies")').catch(_ => { }); // to not waste screen space when non-headless, TODO does not work reliably, need to wait for something else first? 'button:has-text("Sign in")',
while (await page.locator('button:has-text("Sign in")').count() > 0) { 'button:has-text("Anmelden")',
'[data-a-target="user-dropdown-first-name-text"]',
'[data-testid="user-dropdown-first-name-text"]',
].map(s => page.waitForSelector(s)));
try {
await page.click('[aria-label="Cookies usage disclaimer banner"] button:has-text("Accept Cookies")'); // to not waste screen space when non-headless; could be flaky
} catch {
// ignore if banner not present
}
while (await page.locator('button:has-text("Sign in"), button:has-text("Anmelden")').count() > 0) {
console.error('Not signed in anymore.'); console.error('Not signed in anymore.');
await page.click('button:has-text("Sign in")'); await page.click('button:has-text("Sign in")');
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in
@ -52,25 +108,26 @@ try {
const password = email && (cfg.pg_password || await prompt({ type: 'password', message: 'Enter password' })); const password = email && (cfg.pg_password || await prompt({ type: 'password', message: 'Enter password' }));
if (email && password) { if (email && password) {
await page.fill('[name=email]', email); await page.fill('[name=email]', email);
await page.fill('[name=password]', password);
await page.check('[name=rememberMe]');
await page.click('input[type="submit"]'); await page.click('input[type="submit"]');
page.waitForURL('**/ap/signin**').then(async () => { // check for wrong credentials await page.fill('[name=password]', password);
await page.click('input[type="submit"]');
try {
await page.waitForURL('**/ap/signin**');
const error = await page.locator('.a-alert-content').first().innerText(); const error = await page.locator('.a-alert-content').first().innerText();
if (!error.trim.length) return; if (error.trim().length) {
console.error('Login error:', error); console.error('Login error:', error);
await notify(`prime-gaming: login: ${error}`); await notify(`prime-gaming: login: ${error}`);
await context.close(); // finishes potential recording await context.close(); // finishes potential recording
process.exit(1); process.exit(1);
}); }
// handle MFA, but don't await it } catch {
page.waitForURL('**/ap/mfa**').then(async () => { // navigation ok
console.log('Two-Step Verification - enter the One Time Password (OTP), e.g. generated by your Authenticator App'); }
await page.check('[name=rememberDevice]'); try {
const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them await handleMFA(page);
await page.locator('input[name=otpCode]').pressSequentially(otp.toString()); } catch {
await page.click('input[type="submit"]'); // ignore MFA watcher errors
}).catch(_ => { }); }
} else { } else {
console.log('Waiting for you to login in the browser.'); console.log('Waiting for you to login in the browser.');
await notify('prime-gaming: no longer signed in and not enough options set for automatic login.'); await notify('prime-gaming: no longer signed in and not enough options set for automatic login.');
@ -83,11 +140,8 @@ try {
await page.waitForURL('https://gaming.amazon.com/home?signedIn=true'); await page.waitForURL('https://gaming.amazon.com/home?signedIn=true');
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
} }
user = await page.locator('[data-a-target="user-dropdown-first-name-text"]').first().innerText(); user = await page.locator('[data-a-target="user-dropdown-first-name-text"], [data-testid="user-dropdown-first-name-text"]').first().innerText();
console.log(`Signed in as ${user}`); console.log(`Signed in as ${user}`);
// await page.click('button[aria-label="User dropdown and more options"]');
// const twitch = await page.locator('[data-a-target="TwitchDisplayName"]').first().innerText();
// console.log(`Twitch user name is ${twitch}`);
db.data[user] ||= {}; db.data[user] ||= {};
if (await page.getByRole('button', { name: 'Try Prime' }).count()) { if (await page.getByRole('button', { name: 'Try Prime' }).count()) {
@ -96,98 +150,359 @@ try {
process.exit(1); process.exit(1);
} }
await page.click('button[data-type="Game"]'); const waitUntilStable = async (f, act) => {
await page.keyboard.press('End'); // scroll to bottom to show all games let v;
while (true) {
const v2 = await f();
console.log('waitUntilStable', v2);
if (v == v2) break;
v = v2;
await act();
}
};
const scrollUntilStable = async f => await waitUntilStable(f, async () => {
// await page.keyboard.press('End'); // scroll to bottom to show all games
// loading all games became flaky; see https://github.com/vogler/free-games-claimer/issues/357
await page.keyboard.press('PageDown'); // scrolling to straight to the bottom started to skip loading some games
await page.waitForLoadState('networkidle'); // wait for all games to be loaded await page.waitForLoadState('networkidle'); // wait for all games to be loaded
await page.waitForTimeout(2000); // TODO networkidle wasn't enough to load all already collected games await page.waitForTimeout(3000); // extra wait to load all already collected games
const games = page.locator('div[data-a-target="offer-list-FGWP_FULL"]'); // do it again since once wasn't enough...
await games.waitFor(); await page.keyboard.press('PageDown');
console.log('Number of already claimed games (total):', await games.locator('p:has-text("Collected")').count()); await page.waitForTimeout(3000);
// can't use .all() since the list of elements via locator will change after click while we iterate over it });
const internal = await games.locator('.item-card__action:has([data-a-target="FGWPOffer"])').elementHandles();
const external = await games.locator('.item-card__action:has([data-a-target="ExternalOfferClaim"])').all(); const openGamesTab = async () => {
console.log('Number of free unclaimed games (Prime Gaming):', internal.length); const selectors = [
'button[data-type="Game"]', // old layout
'button:has-text("Games")',
'button:has-text("Games einlösen")',
'[data-test-selector="category-picker"] button:has-text("Games")',
'[data-testid="category-picker"] button:has-text("Games")',
];
for (const sel of selectors) {
const btn = page.locator(sel).first();
if (await btn.count()) {
await btn.click();
return;
}
}
// New Luna claims home: try the filter/CTA button with embedded <p title="Games einlösen">
const gamesTitle = page.locator('p.offer-filters__button__title:has-text("Games"), p.offer-filters__button__title:has-text("einlösen")');
if (await gamesTitle.count()) {
const btn = gamesTitle.first().locator('xpath=ancestor::button[1]');
if (await btn.count()) {
await btn.click();
return;
}
}
// New Luna claims home already shows games list
};
await openGamesTab();
const locateGamesList = async () => {
const selectors = [
'div[data-a-target="offer-list-FGWP_FULL"]', // old layout
'[data-testid="offer-list"]',
'[data-test-selector="offer-list"]',
'section:has(h2:has-text("Games with Prime"))',
'section:has(h2:has-text("Games"))',
];
for (const sel of selectors) {
const loc = page.locator(sel).first();
if (await loc.count()) return loc;
}
return null;
};
const games = await locateGamesList();
// Load all cards (old and new layout) by scrolling the container or the page
if (games) await scrollUntilStable(() => games.evaluate(el => el.scrollHeight).catch(() => 0));
await scrollUntilStable(() => page.evaluate(() => globalThis.document?.scrollingElement?.scrollHeight ?? 0));
const normalizeClaimUrl = url => {
if (!url) return { url, key: null };
const m = url.match(/(https?:\/\/[^/]+)?(\/claims\/[^?#]+)/);
if (!m) return { url, key: url };
const path = m[2];
const slug = path.split('/')[2];
return { url: 'https://luna.amazon.com' + path, key: slug || path };
};
const cards = [];
// New layout: direct claim buttons on cards (FGWPOffer) with "Spiel aktivieren"/"Claim"
const fgwps = page.locator('[data-a-target="FGWPOffer"]');
if (await fgwps.count()) {
for (const handle of await fgwps.elementHandles()) {
const href = await handle.getAttribute('href');
const { url, key } = normalizeClaimUrl(href?.startsWith('/') ? href : href || '');
const title =
await handle.$eval('p[title], span[title]', el => el.getAttribute('title')).catch(() => null) ||
await handle.$eval('p, span', el => el.textContent).catch(() => null) ||
key ||
'Unknown title';
cards.push({ kind: 'external', title, url, key });
}
}
const anchorClaims = page.locator('a[href*="/claims/"][href*="amzn1.pg.item"]');
if (await anchorClaims.count()) {
const hrefs = [...new Set(await anchorClaims.evaluateAll(anchors => anchors.map(a => a.getAttribute('href')).filter(Boolean)))];
for (const href of hrefs) {
const { url, key } = normalizeClaimUrl(href);
const title = key || await anchorClaims.first().innerText() || 'Unknown title';
cards.push({ kind: 'external', title, url, key });
}
}
if (!cards.length && games) {
const cardLocator = games.locator([
'[data-testid="offer-card"]',
'[data-test-selector="offer-card"]',
'.item-card__action',
].join(','));
if (await cardLocator.count() === 0) {
console.log('No games found in list.');
} else {
for (const handle of await cardLocator.elementHandles()) {
const text = (await handle.textContent() || '').toLowerCase();
if (text.includes('collected')) continue; // skip already claimed
const title = await (await handle.$('h3, h4, [data-testid="item-card-title"], [data-test-selector="item-card-title"], .item-card-details__body__primary'))?.innerText() || 'Unknown title';
const linkEl = await handle.$('a[href]');
let url = linkEl && await linkEl.getAttribute('href');
if (url?.startsWith('/')) url = 'https://luna.amazon.com' + url;
const { url: normUrl, key } = normalizeClaimUrl(url);
const hasLinkClaim = await handle.$('a:has-text("Claim"), a:has-text("Get"), a:has-text("Details")');
const hasButtonClaim = await handle.$('button:has-text("Claim"), button:has-text("Get"), button:has-text("Get game"), button:has-text("Play")');
const hasGermanCTA = await handle.$(':is(button,p,a):has-text("Spiel aktivieren"), :is(button,p,a):has-text("Spiel holen")');
if (hasLinkClaim || hasGermanCTA) cards.push({ kind: 'external', title, url: normUrl, key });
else if (hasButtonClaim) cards.push({ kind: 'internal', title, url: normUrl, key, handle });
}
}
}
// dedup by URL to avoid duplicates from multiple selectors
const seenUrl = new Set();
const uniq = cards.filter(c => {
const key = c.key || c.url || c.title;
if (seenUrl.has(key)) return false;
seenUrl.add(key);
return true;
});
const internal = uniq.filter(c => c.kind == 'internal');
const external = uniq.filter(c => c.kind == 'external');
// bottom to top: oldest to newest games
internal.reverse();
external.reverse();
const sameOrNewPage = async url => {
const isNew = page.url() != url;
let p = page;
if (isNew) {
p = await context.newPage();
await p.goto(url, { waitUntil: 'domcontentloaded' });
}
return [p, isNew];
};
const skipBasedOnTime = async url => {
const [p, isNew] = await sameOrNewPage(url);
const dueDateLoc = p.locator('.availability-date .tw-bold, [data-testid="availability-end-date"], [data-test-selector="availability-end-date"]');
if (!await dueDateLoc.count()) {
if (isNew) await p.close();
return false;
}
const dueDateOrg = await dueDateLoc.first().innerText();
const dueDate = new Date(Date.parse(dueDateOrg + ' 17:00'));
const daysLeft = (dueDate.getTime() - Date.now()) / 1000 / 60 / 60 / 24;
const availabilityText = await p.locator('.availability-date, [data-testid="availability-end-date"], [data-test-selector="availability-end-date"]').first().innerText().catch(() => dueDateOrg);
console.log(' ', availabilityText, '->', daysLeft.toFixed(2));
if (isNew) await p.close();
return daysLeft > cfg.pg_timeLeft;
};
console.log('\nNumber of free unclaimed games (Prime Gaming):', internal.length);
// claim games in internal store // claim games in internal store
for (const card of internal) { for (const card of internal) {
await card.scrollIntoViewIfNeeded(); await card.handle.scrollIntoViewIfNeeded();
const title = await (await card.$('.item-card-details__body__primary')).innerText(); const title = card.title;
console.log('Current free game:', title); const url = card.url;
console.log('Current free game:', chalk.blue(title));
if (cfg.pg_timeLeft && url && await skipBasedOnTime(url)) continue;
if (cfg.dryrun) continue; if (cfg.dryrun) continue;
if (cfg.interactive && !await confirm()) continue; if (cfg.interactive) {
await (await card.$('.tw-button:has-text("Claim")')).click(); const confirmed = await confirm();
db.data[user][title] ||= { title, time: datetime(), store: 'internal' }; if (!confirmed) continue;
notify_games.push({ title, status: 'claimed', url: URL_CLAIM });
// const img = await (await card.$('img.tw-image')).getAttribute('src');
// console.log('Image:', img);
await card.screenshot({ path: screenshot('internal', `${filenamify(title)}.png`) });
} }
console.log('Number of free unclaimed games (external stores):', external.length); await card.handle.locator('.tw-button:has-text("Claim"), .tw-button:has-text("Get"), button:has-text("Claim"), button:has-text("Get")').first().click();
db.data[user][title] ||= { title, time: datetime(), url, store: 'internal' };
notify_games.push({ title, status: 'claimed', url });
await card.handle.screenshot({ path: screenshot('internal', `${filenamify(title)}.png`) });
}
console.log('\nNumber of free unclaimed games (external stores):', external.length);
// claim games in external/linked stores. Linked: origin.com, epicgames.com; Redeem-key: gog.com, legacygames.com, microsoft // claim games in external/linked stores. Linked: origin.com, epicgames.com; Redeem-key: gog.com, legacygames.com, microsoft
const external_info = []; const external_info = [];
for (const card of external) { // need to get data incl. URLs in this loop and then navigate in another, otherwise .all() would update after coming back and .elementHandles() like above would lead to error due to page navigation: elementHandle.$: Protocol error (Page.adoptNode) for (const card of external) { // need to get data incl. URLs in this loop and then navigate in another, otherwise .all() would update after coming back and .elementHandles() like above would lead to error due to page navigation: elementHandle.$: Protocol error (Page.adoptNode)
const title = await card.locator('.item-card-details__body__primary').innerText(); const title = card.title;
const slug = await card.locator('a:has-text("Claim")').first().getAttribute('href'); const url = card.url ? card.url.split('?')[0] : undefined;
const url = 'https://gaming.amazon.com' + slug.split('?')[0]; if (!url) continue;
// await (await card.$('text=Claim')).click(); // goes to URL of game, no need to wait
external_info.push({ title, url }); external_info.push({ title, url });
} }
const clickCTA = async p => {
const candidates = [
p.locator('button[data-a-target="buy-box_call-to-action"]').first(),
p.locator('[data-a-target="buy-box_call-to-action"]').first(),
p.locator('[data-a-target="buy-box"] .tw-button:has-text("Get game")').first(),
p.locator('[data-a-target="buy-box"] .tw-button:has-text("Claim")').first(),
p.locator('.tw-button:has-text("Complete Claim")').first(),
p.locator('[data-a-target="buy-box_call-to-action-text"]').first().locator('xpath=ancestor::button[1]'),
p.locator('.tw-button:has-text("Spiel holen"), .tw-button:has-text("Spiel aktivieren")').first(),
p.locator('p:has-text("Spiel holen"), p:has-text("Spiel aktivieren")').first().locator('xpath=ancestor::button[1]'),
];
for (const c of candidates) {
if (await c.count()) {
try {
await c.waitFor({ state: 'visible', timeout: 5000 });
const enabled = await c.isEnabled();
if (enabled) await c.click();
else {
await c.evaluate(el => {
el.disabled = false;
el.removeAttribute('disabled');
el.click();
});
}
return true;
} catch {
// try next candidate
}
}
}
return false;
};
for (const { title, url } of external_info) { for (const { title, url } of external_info) {
console.log('Current free game:', title); // , url); console.log('Current free game:', chalk.blue(title)); // , url);
const existingStatus = db.data[user]?.[title]?.status;
if (existingStatus && !existingStatus.startsWith('failed')) {
console.log(` Already recorded as ${existingStatus}, skipping.`);
notify_games.push({ title, url, status: 'existed' });
continue;
}
await page.goto(url, { waitUntil: 'domcontentloaded' }); await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('[data-a-target="buy-box"]', { timeout: 10000 }).catch(() => {});
if (cfg.debug) await page.pause(); if (cfg.debug) await page.pause();
if (cfg.dryrun) continue; let store = 'unknown';
if (cfg.interactive && !await confirm()) continue; const detailLoc = page.locator('[data-a-target="DescriptionItemDetails"], [data-testid="DescriptionItemDetails"]');
await Promise.any([page.click('.tw-button:has-text("Get game")'), page.click('.tw-button:has-text("Claim")'), page.click('.tw-button:has-text("Complete Claim")'), page.waitForSelector('div:has-text("Link game account")'), page.waitForSelector('.thank-you-title:has-text("Success")')]); // waits for navigation if (await detailLoc.count()) {
const item_text = await detailLoc.first().innerText();
// TODO would be simpler than the below, but will block for linked stores without code const lower = item_text.toLowerCase();
// const redeem_text = await page.textContent('text=/ code on /'); // FAQ: How do I redeem my code? const onPos = lower.lastIndexOf(' on ');
// console.log(' ', redeem_text); if (onPos >= 0) store = lower.slice(onPos + 4).replace(/[.!]$/, '');
// // Before July 29, 2023, redeem your offer code on GOG.com. } else if (url.includes('/claims/')) {
// // Before July 1, 2023, redeem your product code on Legacy Games. const slug = url.split('/claims/')[1]?.split('/')[0] || '';
// let store = redeem_text.toLowerCase().replace(/.* on /, '').slice(0, -1); if (slug.includes('gog')) store = 'gog.com';
else if (slug.includes('epic')) store = 'epic-games';
let store = ''; else if (slug.includes('origin')) store = 'origin';
const store_text = await page.$('[data-a-target="hero-header-subtitle"]'); // worked fine for every store, but now no longer works for gog.com else if (slug.includes('xbox') || slug.includes('microsoft')) store = 'microsoft store';
if (store_text) { // legacy games, ? else if (slug.includes('legacy')) store = 'legacy games';
const store_texts = await store_text.innerText(); const lunaPlay = await page.locator('[data-a-target="LunaOffer"], button[data-a-target="LunaOffer"], button:has-text("Spielen")').count();
// Full game for PC [and MAC] on: Legacy Games, Origin, EPIC GAMES, Battle.net; alt: 3 Full PC Games on Legacy Games if (store == 'unknown' && lunaPlay) store = 'luna';
store = store_texts.toLowerCase().replace(/.* on /, '');
} else { // gog.com, ?
// $('[data-a-target="DescriptionItemDetails"]').innerText is e.g. 'Prey for PC on GOG.com.' but does not work for Legacy Games
const item_text = await page.innerText('[data-a-target="DescriptionItemDetails"]');
store = item_text.toLowerCase().replace(/.* on /, '').slice(0, -1);
} }
console.log(' External store:', store); console.log(' External store:', store);
db.data[user][title] ||= { title, time: datetime(), url, store };
const notify_game = { title, url }; const notify_game = { title, url };
notify_games.push(notify_game); // status is updated below notify_games.push(notify_game); // status is updated below
if (await page.locator('div:has-text("Link game account")').count() // TODO still needed? epic games store just has 'Link account' as the button text now. // Already collected? skip
const collectedLoc = page.locator('[data-a-target="ClaimStateQuantityAndDateContent"], [data-a-target="ClaimStateClaimCodeContent"]:has-text("Collected"), [data-a-target="ClaimStateVendorContent"], [data-a-target="ClaimStateViewDetailsAndInstructions"]');
const collectedText = page.getByText(/You collected this on/i);
const collectedEpic = page.getByText(/Sent to your Epic Games Store library/i);
const collectedBanner = page.locator('p.tw-c-text-alert-success:has-text("Collected"), p.tw-c-text-alert-success:has-text("Collected this")');
const collectedSuccessIcon = page.locator('[data-a-target="ItemCardDetailSuccessStatus"], .claim-state__success-icon');
const disabledCTA = page.locator('[data-a-target="buy-box_call-to-action"][disabled], button[disabled]:has-text("Get game")');
const collectedAny = await Promise.all([
collectedLoc.count(),
collectedBanner.count(),
collectedText.count(),
collectedEpic.count(),
collectedSuccessIcon.count(),
disabledCTA.count(),
]).then(([a, b, c, d, e, f]) => a + b + c + d + e + f > 0);
if (collectedAny) {
console.log(' Already collected, skipping.');
notify_game.status = 'existed';
db.data[user][title] ||= { title, time: datetime(), url, store, status: 'existed' };
continue;
}
// Disabled CTA (e.g., needs linking or not available)
if (await disabledCTA.count()) {
if (store !== 'epic-games') {
console.log(' CTA is disabled, skipping (likely needs linking/not available).');
notify_game.status = 'disabled';
db.data[user][title] ||= { title, time: datetime(), url, store, status: 'disabled' };
continue;
} else {
console.log(' CTA disabled for epic-games, will still try to link/claim.');
}
}
if (store == 'luna') {
console.log(' Luna cloud title detected, skipping code redemption.');
notify_game.status = 'luna (play)';
db.data[user][title] ||= { title, time: datetime(), url, store: 'luna', status: 'luna (play)' };
continue;
}
if (cfg.pg_timeLeft && await skipBasedOnTime(url)) continue;
if (cfg.dryrun) continue;
if (cfg.interactive) {
const confirmed = await confirm();
if (!confirmed) continue;
}
await clickCTA(page);
await Promise.any([
page.waitForSelector('.thank-you-title:has-text("Success")', { timeout: cfg.timeout }).catch(() => {}),
page.waitForSelector('div:has-text("Link game account")', { timeout: cfg.timeout }).catch(() => {}),
]).catch(() => {});
db.data[user][title] ||= { title, time: datetime(), url, store };
if (await page.locator('div:has-text("Link game account")').count() // epic games store also shows "Link account"
|| await page.locator('div:has-text("Link account")').count()) { || await page.locator('div:has-text("Link account")').count()) {
console.error(' Account linking is required to claim this offer!'); console.error(' Account linking is required to claim this offer!');
notify_game.status = `failed: need account linking for ${store}`; notify_game.status = `failed: need account linking for ${store}`;
db.data[user][title].status = 'failed: need account linking'; db.data[user][title].status = 'failed: need account linking';
// await page.pause(); // await page.pause();
// await page.click('[data-a-target="LinkAccountModal"] [data-a-target="LinkAccountButton"]'); // await page.click('[data-a-target="LinkAccountModal"] [data-a-target="LinkAccountButton"]');
// TODO login for epic games also needed if already logged in // login for epic games also needed if already logged in
// wait for https://www.epicgames.com/id/authorize?redirect_uri=https%3A%2F%2Fservice.link.amazon.gg... // wait for https://www.epicgames.com/id/authorize?redirect_uri=https%3A%2F%2Fservice.link.amazon.gg...
// await page.click('button[aria-label="Allow"]'); // await page.click('button[aria-label="Allow"]');
} else { } else {
db.data[user][title].status = 'claimed'; db.data[user][title].status = 'claimed';
// print code if there is one // print code if there is one
const redeem = { const redeem = {
// 'origin': 'https://www.origin.com/redeem', // TODO still needed or now only via account linking? // 'origin': 'https://www.origin.com/redeem', // kept for legacy flows; current path uses account linking
'gog.com': 'https://www.gog.com/redeem', 'gog.com': 'https://www.gog.com/redeem',
'microsoft games': 'https://redeem.microsoft.com', 'microsoft store': 'https://account.microsoft.com/billing/redeem',
xbox: 'https://account.microsoft.com/billing/redeem',
'legacy games': 'https://www.legacygames.com/primedeal', 'legacy games': 'https://www.legacygames.com/primedeal',
}; };
if (store in redeem) { // did not work for linked origin: && !await page.locator('div:has-text("Successfully Claimed")').count() if (store in redeem) { // did not work for linked origin: && !await page.locator('div:has-text("Successfully Claimed")').count()
const code = await Promise.any([page.inputValue('input[type="text"]'), page.textContent('[data-a-target="ClaimStateClaimCodeContent"]').then(s => s.replace('Your code: ', ''))]); // input: Legacy Games; text: gog.com let code;
try {
// ensure CTA was clicked in case code is behind it
await clickCTA(page).catch(() => {});
code = await Promise.any([
page.inputValue('input[type="text"]'),
page.textContent('[data-a-target="ClaimStateClaimCodeContent"]').then(s => s.replace('Your code: ', '')),
]);
} catch {
console.error(' Could not find claim code on page (timeout). Please check manually.');
db.data[user][title].status = 'claimed (code not found)';
notify_game.status = 'claimed (code not found)';
await page.screenshot({ path: screenshot('external', `${filenamify(title)}_nocode.png`), fullPage: true }).catch(() => {});
continue;
}
console.log(' Code to redeem game:', chalk.blue(code)); console.log(' Code to redeem game:', chalk.blue(code));
if (store == 'legacy games') { // may be different URL like https://legacygames.com/primeday/puzzleoftheyear/ if (store == 'legacy games') { // may be different URL like https://legacygames.com/primeday/puzzleoftheyear/
redeem[store] = await (await page.$('li:has-text("Click here") a')).getAttribute('href'); // full text: Click here to enter your redemption code. redeem[store] = await (await page.$('li:has-text("Click here") a')).getAttribute('href'); // full text: Click here to enter your redemption code.
} }
console.log(' URL to redeem game:', redeem[store]); let redeem_url = redeem[store];
if (store == 'gog.com') redeem_url += '/' + code; // to log and notify, but can't use for goto below (captcha)
console.log(' URL to redeem game:', redeem_url);
db.data[user][title].code = code; db.data[user][title].code = code;
let redeem_action = 'redeem'; let redeem_action = 'redeem';
if (cfg.pg_redeem) { // try to redeem keys on external stores if (cfg.pg_redeem) { // try to redeem keys on external stores
@ -195,13 +510,9 @@ try {
const page2 = await context.newPage(); const page2 = await context.newPage();
await page2.goto(redeem[store], { waitUntil: 'domcontentloaded' }); await page2.goto(redeem[store], { waitUntil: 'domcontentloaded' });
if (store == 'gog.com') { if (store == 'gog.com') {
// await page.goto(`https://redeem.gog.com/v1/bonusCodes/${code}`); // {"reason":"Invalid or no captcha"}
await page2.fill('#codeInput', code); await page2.fill('#codeInput', code);
// wait for responses before clicking on Continue and then Redeem
// first there are requests with OPTIONS and GET to https://redeem.gog.com/v1/bonusCodes/XYZ?language=de-DE
const r1 = page2.waitForResponse(r => r.request().method() == 'GET' && r.url().startsWith('https://redeem.gog.com/')); const r1 = page2.waitForResponse(r => r.request().method() == 'GET' && r.url().startsWith('https://redeem.gog.com/'));
await page2.click('[type="submit"]'); // click Continue await page2.click('[type="submit"]'); // click Continue
// console.log(await page2.locator('.warning-message').innerText()); // does not exist if there is no warning
const r1t = await (await r1).text(); const r1t = await (await r1).text();
const reason = JSON.parse(r1t).reason; const reason = JSON.parse(r1t).reason;
// {"reason":"Invalid or no captcha"} // {"reason":"Invalid or no captcha"}
@ -216,54 +527,69 @@ try {
} else if (reason == 'code_not_found') { } else if (reason == 'code_not_found') {
redeem_action = 'redeem (not found)'; redeem_action = 'redeem (not found)';
console.error(' Code was not found!'); console.error(' Code was not found!');
} else { // TODO not logged in? need valid unused code to test. } else { // unknown state; keep info log for later analysis
redeem_action = 'redeemed?'; redeem_action = 'redeemed?';
// console.log(' Redeemed successfully? Please report your Responses (if new) in https://github.com/vogler/free-games-claimer/issues/5');
console.debug(` Response 1: ${r1t}`); console.debug(` Response 1: ${r1t}`);
// then after the click on Redeem there is a POST request which should return {} if claimed successfully
const r2 = page2.waitForResponse(r => r.request().method() == 'POST' && r.url().startsWith('https://redeem.gog.com/')); const r2 = page2.waitForResponse(r => r.request().method() == 'POST' && r.url().startsWith('https://redeem.gog.com/'));
await page2.click('[type="submit"]'); // click Redeem await page2.click('[type="submit"]'); // click Redeem
const r2t = await (await r2).text(); const r2t = await (await r2).text();
const reason2 = JSON.parse(r2t).reason;
if (r2t == '{}') { if (r2t == '{}') {
redeem_action = 'redeemed'; redeem_action = 'redeemed';
console.log(' Redeemed successfully.'); console.log(' Redeemed successfully.');
db.data[user][title].status = 'claimed and redeemed'; db.data[user][title].status = 'claimed and redeemed';
} else if (reason2?.includes('captcha')) {
redeem_action = 'redeem (got captcha)';
console.error(' Got captcha; could not redeem!');
} else { } else {
console.debug(` Response 2: ${r2t}`); console.debug(` Response 2: ${r2t}`);
console.log(' Unknown Response 2 - please report in https://github.com/vogler/free-games-claimer/issues/5'); console.log(' Unknown Response 2 - please report in https://github.com/vogler/free-games-claimer/issues/5');
} }
} }
} else if (store == 'microsoft games') { } else if (store == 'microsoft store' || store == 'xbox') {
console.error(` Redeem on ${store} not yet implemented!`); console.error(` Redeem on ${store} is experimental!`);
if (page2.url().startsWith('https://login.')) { if (page2.url().startsWith('https://login.')) {
console.error(' Not logged in! Use the browser to login manually.'); console.error(' Not logged in! Please redeem the code above manually. You can now login in the browser for next time. Waiting for 60s.');
await page2.waitForTimeout(60 * 1000);
redeem_action = 'redeem (login)'; redeem_action = 'redeem (login)';
} else { } else {
const r = page2.waitForResponse(r => r.url().startsWith('https://purchase.mp.microsoft.com/')); const iframe = page2.frameLocator('#redeem-iframe');
await page2.fill('[name=tokenString]', code); const input = iframe.locator('[name=tokenString]');
// console.log(await page2.locator('.redeem_code_error').innerText()); await input.waitFor();
await input.fill(code);
const r = page2.waitForResponse(r => r.url().startsWith('https://cart.production.store-web.dynamics.com/v1.0/Redeem/PrepareRedeem'));
const rt = await (await r).text(); const rt = await (await r).text();
console.debug(` Response: ${rt}`); const j = JSON.parse(rt);
// {"code":"NotFound","data":[],"details":[],"innererror":{"code":"TokenNotFound",... const reason = j?.events?.cart.length && j.events.cart[0]?.data?.reason;
const reason = JSON.parse(rt).code; if (reason == 'TokenNotFound') {
if (reason == 'NotFound') {
redeem_action = 'redeem (not found)'; redeem_action = 'redeem (not found)';
console.error(' Code was not found!'); console.error(' Code was not found!');
} else { // TODO find out other responses } else if (j?.productInfos?.length && j.productInfos[0]?.redeemable) {
await page2.click('#nextButton'); await iframe.locator('button:has-text("Next")').click();
redeem_action = 'redeemed?'; await iframe.locator('button:has-text("Confirm")').click();
console.log(' Redeemed successfully? Please report your Response from above (if it is new) in https://github.com/vogler/free-games-claimer/issues/5'); const r = page2.waitForResponse(r => r.url().startsWith('https://cart.production.store-web.dynamics.com/v1.0/Redeem/RedeemToken'));
const j = JSON.parse(await (await r).text());
if (j?.events?.cart.length && j.events.cart[0]?.data?.reason == 'UserAlreadyOwnsContent') {
redeem_action = 'already redeemed';
console.error(' error: UserAlreadyOwnsContent');
} else { // success path not seen yet; log below if needed
redeem_action = 'redeemed';
db.data[user][title].status = 'claimed and redeemed?'; db.data[user][title].status = 'claimed and redeemed?';
console.log(' Redeemed successfully? Please report if not in https://github.com/vogler/free-games-claimer/issues/5');
}
} else { // other responses; keep info log for analysis
redeem_action = 'unknown';
console.debug(` Response: ${rt}`);
console.log(' Redeemed successfully? Please report your Response from above (if it is new) in https://github.com/vogler/free-games-claimer/issues/5');
} }
} }
} else if (store == 'legacy games') { } else if (store == 'legacy games') {
await page2.fill('[name=coupon_code]', code); await page2.fill('[name=coupon_code]', code);
await page2.fill('[name=email]', cfg.pg_email); // TODO option for sep. email? await page2.fill('[name=email]', cfg.lg_email);
await page2.fill('[name=email_validate]', cfg.pg_email); await page2.fill('[name=email_validate]', cfg.lg_email);
await page2.uncheck('[name=newsletter_sub]'); await page2.uncheck('[name=newsletter_sub]');
await page2.click('[type="submit"]'); await page2.click('[type="submit"]');
try { try {
// await page2.waitForResponse(r => r.url().startsWith('https://promo.legacygames.com/promotion-processing/order-management.php')); // status code 302
await page2.waitForSelector('h2:has-text("Thanks for redeeming")'); await page2.waitForSelector('h2:has-text("Thanks for redeeming")');
redeem_action = 'redeemed'; redeem_action = 'redeemed';
db.data[user][title].status = 'claimed and redeemed'; db.data[user][title].status = 'claimed and redeemed';
@ -279,25 +605,24 @@ try {
if (cfg.debug) await page2.pause(); if (cfg.debug) await page2.pause();
await page2.close(); await page2.close();
} }
notify_game.status = `<a href="${redeem[store]}">${redeem_action}</a> ${code} on ${store}`; notify_game.status = `<a href="${redeem_url}">${redeem_action}</a> ${code} on ${store}`;
} else { } else {
notify_game.status = `claimed on ${store}`; notify_game.status = `claimed on ${store}`;
db.data[user][title].status = 'claimed'; db.data[user][title].status = 'claimed';
} }
// save screenshot of potential code just in case
await page.screenshot({ path: screenshot('external', `${filenamify(title)}.png`), fullPage: true }); await page.screenshot({ path: screenshot('external', `${filenamify(title)}.png`), fullPage: true });
// console.info(' Saved a screenshot of page to', p);
} }
// await page.pause();
} }
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
try {
await page.click('button[data-type="Game"]'); await page.click('button[data-type="Game"]');
} catch {
// ignore if filter already selected
}
if (notify_games.length) { // make screenshot of all games if something was claimed if (notify_games.length && games) { // make screenshot of all games if something was claimed and list exists
const p = screenshot(`${filenamify(datetime())}.png`); const p = screenshot(`${filenamify(datetime())}.png`);
// await page.screenshot({ path: p, fullPage: true }); // fullPage does not make a difference since scroll not on body but on some element await scrollUntilStable(() => games.locator('.item-card__action').count());
await page.keyboard.press('End'); // scroll to bottom to show all games
await page.waitForTimeout(1000); // wait for fade in animation
const viewportSize = page.viewportSize(); // current viewport size const viewportSize = page.viewportSize(); // current viewport size
await page.setViewportSize({ ...viewportSize, height: 3000 }); // increase height, otherwise element screenshot is cut off at the top and bottom await page.setViewportSize({ ...viewportSize, height: 3000 }); // increase height, otherwise element screenshot is cut off at the top and bottom
await games.screenshot({ path: p }); // screenshot of all claimed games await games.screenshot({ path: p }); // screenshot of all claimed games
@ -311,17 +636,7 @@ try {
await loot.waitFor(); await loot.waitFor();
process.stdout.write('Loading all DLCs on page...'); process.stdout.write('Loading all DLCs on page...');
let n1 = 0; await scrollUntilStable(() => loot.locator('[data-a-target="item-card"]').count());
let n2 = 0;
do {
n1 = n2;
n2 = await loot.locator('[data-a-target="item-card"]').count();
// console.log(n2);
process.stdout.write(` ${n2}`);
await page.keyboard.press('End'); // scroll to bottom to show all dlcs
await page.waitForLoadState('networkidle'); // did not wait for dlcs to be loaded
await page.waitForTimeout(1000);
} while (n2 > n1);
console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count()); console.log('\nNumber of already claimed DLC:', await loot.locator('p:has-text("Collected")').count());
@ -349,17 +664,30 @@ try {
await page.goto(url, { waitUntil: 'domcontentloaded' }); await page.goto(url, { waitUntil: 'domcontentloaded' });
// most games have a button 'Get in-game content' // most games have a button 'Get in-game content'
// epic-games: Fall Guys: Claim -> Continue -> Go to Epic Games (despite account linked and logged into epic-games) -> not tied to account but via some cookie? // epic-games: Fall Guys: Claim -> Continue -> Go to Epic Games (despite account linked and logged into epic-games) -> not tied to account but via some cookie?
await Promise.any([page.click('.tw-button:has-text("Get in-game content")'), page.click('.tw-button:has-text("Claim your gift")'), page.click('.tw-button:has-text("Claim")').then(() => page.click('button:has-text("Continue")'))]); const claimOptions = [
page.click('button:has-text("Continue")').catch(_ => { }); page.click('.tw-button:has-text("Get in-game content")'),
page.click('.tw-button:has-text("Claim your gift")'),
(async () => {
await page.click('.tw-button:has-text("Claim")');
await page.click('button:has-text("Continue")').catch(() => {});
})(),
];
await Promise.any(claimOptions);
try {
await page.click('button:has-text("Continue")');
} catch {
// continue button not always present
}
const linkAccountButton = page.locator('[data-a-target="LinkAccountButton"]'); const linkAccountButton = page.locator('[data-a-target="LinkAccountButton"]');
let unlinked_store; let unlinked_store;
if (await linkAccountButton.count()) { if (await linkAccountButton.count()) {
unlinked_store = await linkAccountButton.first().getAttribute('aria-label'); unlinked_store = await linkAccountButton.first().getAttribute('aria-label');
console.debug(' LinkAccountButton label:', unlinked_store); console.debug(' LinkAccountButton label:', unlinked_store);
const match = unlinked_store.match(/Link (.*) account/); const match = unlinked_store?.match(/Link (.*) account/);
if (match && match.length == 2) unlinked_store = match[1]; const extracted = match?.[1];
if (extracted) unlinked_store = extracted;
} else if (await page.locator('text=Link game account').count()) { // epic-games only? } else if (await page.locator('text=Link game account').count()) { // epic-games only?
console.error(' Missing account linking (epic-games specific button?):', await page.locator('button[data-a-target="gms-cta"]').innerText()); // TODO needed? console.error(' Missing account linking (epic-games specific button?):', await page.locator('button[data-a-target="gms-cta"]').innerText()); // track account-linking UI drift
unlinked_store = 'epic-games'; unlinked_store = 'epic-games';
} }
if (unlinked_store) { if (unlinked_store) {
@ -367,13 +695,11 @@ try {
dlc_unlinked[unlinked_store] ??= []; dlc_unlinked[unlinked_store] ??= [];
dlc_unlinked[unlinked_store].push(title); dlc_unlinked[unlinked_store].push(title);
} else { } else {
const code = await page.inputValue('input[type="text"]').catch(_ => undefined); const code = await page.inputValue('input[type="text"]').catch(() => undefined);
console.log(' Code to redeem game:', chalk.blue(code)); console.log(' Code to redeem game:', chalk.blue(code));
db.data[user][title].code = code; db.data[user][title].code = code;
db.data[user][title].status = 'claimed'; db.data[user][title].status = 'claimed';
// notify_game.status = `<a href="${redeem[store]}">${redeem_action}</a> ${code} on ${store}`;
} }
// await page.pause();
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {

View file

@ -41,12 +41,13 @@ export const cfg = {
gog_email: process.env.GOG_EMAIL || process.env.EMAIL, gog_email: process.env.GOG_EMAIL || process.env.EMAIL,
gog_password: process.env.GOG_PASSWORD || process.env.PASSWORD, gog_password: process.env.GOG_PASSWORD || process.env.PASSWORD,
gog_newsletter: process.env.GOG_NEWSLETTER == '1', // do not unsubscribe from newsletter after claiming a game gog_newsletter: process.env.GOG_NEWSLETTER == '1', // do not unsubscribe from newsletter after claiming a game
// auth AliExpress
ae_email: process.env.AE_EMAIL || process.env.EMAIL,
ae_password: process.env.AE_PASSWORD || process.env.PASSWORD,
// OTP only via GOG_EMAIL, can't add app... // OTP only via GOG_EMAIL, can't add app...
// auth xbox // experimmental
xbox_email: process.env.XBOX_EMAIL || process.env.EMAIL,
xbox_password: process.env.XBOX_PASSWORD || process.env.PASSWORD,
xbox_otpkey: process.env.XBOX_OTPKEY,
// experimmental - likely to change
pg_redeem: process.env.PG_REDEEM == '1', // prime-gaming: redeem keys on external stores pg_redeem: process.env.PG_REDEEM == '1', // prime-gaming: redeem keys on external stores
lg_email: process.env.LG_EMAIL || process.env.PG_EMAIL || process.env.EMAIL, // prime-gaming: external: legacy-games: email to use for redeeming
pg_claimdlc: process.env.PG_CLAIMDLC == '1', // prime-gaming: claim in-game content pg_claimdlc: process.env.PG_CLAIMDLC == '1', // prime-gaming: claim in-game content
pg_timeLeft: Number(process.env.PG_TIMELEFT), // prime-gaming: check time left to claim and skip game if there are more than PG_TIMELEFT days left to claim it
}; };

View file

@ -1,4 +1,4 @@
import { existsSync } from 'fs'; import { existsSync } from 'node:fs';
import { Low } from 'lowdb'; import { Low } from 'lowdb';
import { JSONFile } from 'lowdb/node'; import { JSONFile } from 'lowdb/node';
import { datetime } from './util.js'; import { datetime } from './util.js';
@ -18,7 +18,6 @@ const datetime_UTCtoLocalTimezone = async file => {
db.data[user][game].time = time2; db.data[user][game].time = time2;
} }
} }
// console.log(db.data);
await db.write(); // write out json db await db.write(); // write out json db
}; };

View file

@ -11,15 +11,17 @@ export const dataDir = s => path.resolve(__dirname, '..', 'data', s);
export const resolve = (...a) => a.length && a[0] == '0' ? null : path.resolve(...a); export const resolve = (...a) => a.length && a[0] == '0' ? null : path.resolve(...a);
// json database // json database
import { JSONPreset } from 'lowdb/node'; import { JSONFilePreset } from 'lowdb/node';
export const jsonDb = (file, defaultData) => JSONPreset(dataDir(file), defaultData); export const jsonDb = (file, defaultData) => JSONFilePreset(dataDir(file), defaultData);
export const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); export const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
// date and time as UTC (no timezone offset) in nicely readable and sortable format, e.g., 2022-10-06 12:05:27.313 // date and time as UTC (no timezone offset) in nicely readable and sortable format, e.g., 2022-10-06 12:05:27.313
export const datetimeUTC = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', ''); export const datetimeUTC = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', '');
// same as datetimeUTC() but for local timezone, e.g., UTC + 2h for the above in DE // same as datetimeUTC() but for local timezone, e.g., UTC + 2h for the above in DE
export const datetime = (d = new Date()) => datetimeUTC(new Date(d.getTime() - d.getTimezoneOffset() * 60000)); export const datetime = (d = new Date()) => datetimeUTC(new Date(d.getTime() - d.getTimezoneOffset() * 60000));
export const filenamify = s => s.replaceAll(':', '.').replace(/[^a-z0-9 _\-.]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify - On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved. export const filenamify = s => s
.replaceAll(':', '.')
.replaceAll(/[^a-z0-9 _\-.]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify - On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved.
export const handleSIGINT = (context = null) => process.on('SIGINT', async () => { // e.g. when killed by Ctrl-C export const handleSIGINT = (context = null) => process.on('SIGINT', async () => { // e.g. when killed by Ctrl-C
console.error('\nInterrupted by SIGINT. Exit!'); // Exception shows where the script was:\n'); // killed before catch in docker... console.error('\nInterrupted by SIGINT. Exit!'); // Exception shows where the script was:\n'); // killed before catch in docker...
@ -81,7 +83,7 @@ export const stealth = async context => {
const evasion = await import(`puppeteer-extra-plugin-stealth/evasions/${e}/index.js`); const evasion = await import(`puppeteer-extra-plugin-stealth/evasions/${e}/index.js`);
evasion.default().onPageCreated(stealth); evasion.default().onPageCreated(stealth);
} }
for (let evasion of stealth.callbacks) { for (const evasion of stealth.callbacks) {
await context.addInitScript(evasion.cb, evasion.a); await context.addInitScript(evasion.cb, evasion.a);
} }
}; };
@ -90,42 +92,50 @@ export const stealth = async context => {
// alternative inquirer is big (node_modules 29MB, enquirer 9.7MB, prompts 9.8MB, none 9.4MB) and slower // alternative inquirer is big (node_modules 29MB, enquirer 9.7MB, prompts 9.8MB, none 9.4MB) and slower
// open issue: prevents handleSIGINT() to work if prompt is cancelled with Ctrl-C instead of Escape: https://github.com/enquirer/enquirer/issues/372 // open issue: prevents handleSIGINT() to work if prompt is cancelled with Ctrl-C instead of Escape: https://github.com/enquirer/enquirer/issues/372
import Enquirer from 'enquirer'; const enquirer = new Enquirer(); import Enquirer from 'enquirer'; const enquirer = new Enquirer();
const timeoutPlugin = timeout => enquirer => { // cancel prompt after timeout ms const timeoutHint = () => 'timeout';
enquirer.on('prompt', prompt => { const cancelPromptWithHint = prompt => {
const t = setTimeout(() => { prompt.hint = timeoutHint;
prompt.hint = () => 'timeout';
prompt.cancel(); prompt.cancel();
}, timeout);
prompt.on('submit', _ => clearTimeout(t));
prompt.on('cancel', _ => clearTimeout(t));
});
}; };
enquirer.use(timeoutPlugin(cfg.login_timeout)); // TODO may not want to have this timeout for all prompts; better extend Prompt and add a timeout prompt option const applyPromptTimeout = (prompt, timeout) => {
if (!timeout) return;
const timer = setTimeout(cancelPromptWithHint, timeout, prompt);
const clearTimer = () => clearTimeout(timer);
prompt.on('submit', clearTimer);
prompt.on('cancel', clearTimer);
};
// cancel prompt after timeout ms; can be disabled per prompt via options.timeout = 0
const timeoutPlugin = defaultTimeout => enquirerInstance => {
const onPrompt = prompt => applyPromptTimeout(prompt, prompt.options?.timeout ?? defaultTimeout);
enquirerInstance.on('prompt', onPrompt);
};
enquirer.use(timeoutPlugin(cfg.login_timeout));
// single prompt that just returns the non-empty value instead of an object // single prompt that just returns the non-empty value instead of an object
// @ts-ignore // @ts-ignore
export const prompt = o => enquirer.prompt({ name: 'name', type: 'input', message: 'Enter value', ...o }).then(r => r.name).catch(_ => {}); export const prompt = o => enquirer.prompt({ name: 'name', type: 'input', message: 'Enter value', ...o }).then(r => r.name).catch(() => {});
export const confirm = o => prompt({ type: 'confirm', message: 'Continue?', ...o }); export const confirm = o => prompt({ type: 'confirm', message: 'Continue?', ...o });
// notifications via apprise CLI // notifications via apprise CLI
import { execFile } from 'child_process'; import { execFile } from 'node:child_process';
import { cfg } from './config.js'; import { cfg } from './config.js';
export const notify = html => new Promise((resolve, reject) => { export const notify = html => new Promise(resolve => {
if (!cfg.notify) { if (!cfg.notify) {
if (cfg.debug) console.debug('notify: NOTIFY is not set!'); if (cfg.debug) console.debug('notify: NOTIFY is not set!');
return resolve(); return resolve();
} }
// const cmd = `apprise '${cfg.notify}' ${title} -i html -b '${html}'`; // this had problems if e.g. ' was used in arg; could have `npm i shell-escape`, but instead using safer execFile which takes args as array instead of exec which spawned a shell to execute the command const appriseBin = process.env.APPRISE_BIN || '/usr/local/bin/apprise';
const args = [cfg.notify, '-i', 'html', '-b', html]; const args = [cfg.notify, '-i', 'html', '-b', `'${html}'`];
if (cfg.notify_title) args.push(...['-t', cfg.notify_title]); if (cfg.notify_title) args.push('-t', cfg.notify_title);
if (cfg.debug) console.debug(`apprise ${args.map(a => `'${a}'`).join(' ')}`); // this also doesn't escape, but it's just for info if (cfg.debug) console.debug(`${appriseBin} ${args.join(' ')}`); // this also doesn't escape, but it's just for info
execFile('apprise', args, (error, stdout, stderr) => { execFile(appriseBin, args, (error, stdout, stderr) => {
if (error) { if (error) {
console.log(`error: ${error.message}`); console.log(`error: ${error.message}`);
if (error.message.includes('command not found')) { if (error.message.includes('command not found')) {
console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications'); console.info('Run `pip install apprise`. See https://github.com/vogler/free-games-claimer#notifications');
} }
return reject(error); // don't fail the whole run on notification errors
return resolve();
} }
if (stderr) console.error(`stderr: ${stderr}`); if (stderr) console.error(`stderr: ${stderr}`);
if (stdout) console.log(`stdout: ${stdout}`); if (stdout) console.log(`stdout: ${stdout}`);

View file

@ -1,15 +1,14 @@
// check if running the latest version import { log } from 'node:console';
import { execFile } from 'node:child_process';
import { log } from 'console'; const gitBin = process.env.GIT_BIN || '/usr/bin/git';
import { exec } from 'child_process';
const execp = cmd => new Promise((resolve, reject) => { const runGit = (...args) => new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => { execFile(gitBin, args, { cwd: process.cwd() }, (error, stdout, stderr) => {
if (stderr) console.error(`stderr: ${stderr}`); if (stderr) console.error(`stderr: ${stderr}`);
// if (stdout) console.log(`stdout: ${stdout}`);
if (error) { if (error) {
console.log(`error: ${error.message}`); console.log(`error: ${error.message}`);
if (error.message.includes('command not found')) { if (error.code === 'ENOENT' || error.message.includes('command not found')) {
console.info('Install git to check for updates!'); console.info('Install git to check for updates!');
} }
return reject(error); return reject(error);
@ -18,10 +17,7 @@ const execp = cmd => new Promise((resolve, reject) => {
}); });
}); });
// const git_main = () => readFileSync('.git/refs/heads/main').toString().trim();
let sha, date; let sha, date;
// if (existsSync('/.dockerenv')) { // did not work
if (process.env.NOVNC_PORT) { if (process.env.NOVNC_PORT) {
log('Running inside Docker.'); log('Running inside Docker.');
['COMMIT', 'BRANCH', 'NOW'].forEach(v => log(` ${v}:`, process.env[v])); ['COMMIT', 'BRANCH', 'NOW'].forEach(v => log(` ${v}:`, process.env[v]));
@ -29,15 +25,11 @@ if (process.env.NOVNC_PORT) {
date = process.env.NOW; date = process.env.NOW;
} else { } else {
log('Not running inside Docker.'); log('Not running inside Docker.');
sha = await execp('git rev-parse HEAD'); sha = await runGit('rev-parse', 'HEAD');
date = await execp('git show -s --format=%cD'); // same as format as `date -R` (RFC2822) date = await runGit('show', '-s', '--format=%cD'); // same as format as `date -R` (RFC2822)
// date = await execp('git show -s --format=%ch'); // %ch is same as --date=human (short/relative)
} }
const gh = await (await fetch('https://api.github.com/repos/vogler/free-games-claimer/commits/main', { const gh = await (await fetch('https://api.github.com/repos/vogler/free-games-claimer/commits/main')).json();
// headers: { accept: 'application/vnd.github.VERSION.sha' }
})).json();
// log(gh);
log('Local commit:', sha, new Date(date)); log('Local commit:', sha, new Date(date));
log('Online commit:', gh.sha, new Date(gh.commit.committer.date)); log('Online commit:', gh.sha, new Date(gh.commit.committer.date));

70
steam-games.js Normal file
View file

@ -0,0 +1,70 @@
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
import { jsonDb, prompt } from './src/util.js';
import { cfg } from './src/config.js';
const db = await jsonDb('steam-games.json', {});
const user = cfg.steam_id || await prompt({ message: 'Enter Steam community id ("View my profile", then copy from URL)' });
// using https://github.com/apify/fingerprint-suite worked, but has no launchPersistentContext...
// from https://github.com/apify/fingerprint-suite/issues/162
import { FingerprintInjector } from 'fingerprint-injector';
import { FingerprintGenerator } from 'fingerprint-generator';
const { fingerprint, headers } = new FingerprintGenerator().getFingerprint({
devices: ['desktop'],
operatingSystems: ['windows'],
});
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless,
locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
userAgent: fingerprint.navigator.userAgent,
viewport: {
width: fingerprint.screen.width,
height: fingerprint.screen.height,
},
extraHTTPHeaders: {
'accept-language': headers['accept-language'],
},
});
await new FingerprintInjector().attachFingerprintToPlaywright(context, { fingerprint, headers });
context.setDefaultTimeout(cfg.debug ? 0 : cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
try {
await page.goto(`https://steamcommunity.com/id/${user}/games?tab=all`);
const games = page.locator('div[data-featuretarget="gameslist-root"] > div.Panel > div.Panel > div');
await games.last().waitFor();
await page.keyboard.press('End');
await page.waitForLoadState('networkidle');
console.log('All Games:', await games.count());
for (const game of await games.all()) {
const title = await game.locator('span a').innerText();
let time, last, achievements, size;
const ltime = game.locator('span:has-text("total played")');
if (await ltime.count()) time = (await ltime.first().innerText()).split('\n')[1];
const llast = game.locator('span:has-text("last played")');
if (await llast.count()) last = (await llast.first().innerText()).split('\n')[1];
const lachievements = game.locator('a:has-text("achievements") + span');
if (await lachievements.count()) achievements = (await lachievements.first().innerText()).split('\n');
const lsize = game.locator('span:has(+ button)');
if (await lsize.count()) size = await lsize.first().innerText();
const url = await game.locator('a').first().getAttribute('href');
const img = await game.locator('img').first().getAttribute('src');
const stat = { title, time, last, achievements, size, url, img };
console.log(stat);
db.data[title] = stat;
}
} catch (error) {
process.exitCode ||= 1;
console.error('--- Exception:');
console.error(error); // .toString()?
} finally {
await db.write(); // write out json db
}
if (page.video()) console.log('Recorded video:', await page.video().path());
await context.close();

View file

@ -1,23 +1,23 @@
/* eslint-disable no-constant-condition */ import { delay, html_game_list, notify } from '../src/util.js';
import { delay, html_game_list, notify } from '../util.js'; import { cfg } from '../src/config.js';
import { cfg } from '../config.js';
const URL_CLAIM = 'https://gaming.amazon.com/home'; // dummy URL const URL_CLAIM = 'https://gaming.amazon.com/home'; // dummy URL
console.debug('NOTIFY:', cfg.notify); console.debug('NOTIFY:', cfg.notify);
if (true) { const scenarios = [
const notify_games = [ {
// { title: 'Kerbal Space Program', status: 'claimed', url: URL_CLAIM }, enabled: process.env.TEST_NOTIFY_EPIC === '1',
// { title: "Shadow Tactics - Aiko's Choice", status: 'claimed', url: URL_CLAIM }, title: 'epic-games',
games: [
{ title: 'Epistory - Typing Chronicles', status: 'claimed', url: URL_CLAIM }, { title: 'Epistory - Typing Chronicles', status: 'claimed', url: URL_CLAIM },
]; ],
await notify(`epic-games:<br>${html_game_list(notify_games)}`); },
} {
enabled: process.env.TEST_NOTIFY_PG === '1',
if (false) { delayMs: 1000,
await delay(1000); title: 'prime-gaming',
const notify_games = [ games: [
{ title: 'Faraway 2: Jungle Escape', status: 'claimed', url: URL_CLAIM }, { title: 'Faraway 2: Jungle Escape', status: 'claimed', url: URL_CLAIM },
{ title: 'Chicken Police - Paint it RED!', status: 'claimed', url: URL_CLAIM }, { title: 'Chicken Police - Paint it RED!', status: 'claimed', url: URL_CLAIM },
{ title: 'Lawn Mowing Simulator', status: 'claimed', url: URL_CLAIM }, { title: 'Lawn Mowing Simulator', status: 'claimed', url: URL_CLAIM },
@ -25,14 +25,18 @@ if (false) {
{ title: 'The Evil Within 2', status: `<a href="${URL_CLAIM}">redeem</a> H97S6FB38FA6D09DEA on gog.com`, url: URL_CLAIM }, { title: 'The Evil Within 2', status: `<a href="${URL_CLAIM}">redeem</a> H97S6FB38FA6D09DEA on gog.com`, url: URL_CLAIM },
{ title: 'Beat Cop', status: `<a href="${URL_CLAIM}">redeem</a> BMKM8558EC55F7B38F on gog.com`, url: URL_CLAIM }, { title: 'Beat Cop', status: `<a href="${URL_CLAIM}">redeem</a> BMKM8558EC55F7B38F on gog.com`, url: URL_CLAIM },
{ title: 'Dishonored 2', status: `<a href="${URL_CLAIM}">redeem</a> NNEK0987AB20DFBF8F on gog.com`, url: URL_CLAIM }, { title: 'Dishonored 2', status: `<a href="${URL_CLAIM}">redeem</a> NNEK0987AB20DFBF8F on gog.com`, url: URL_CLAIM },
]; ],
notify(`prime-gaming:<br>${html_game_list(notify_games)}`); },
} {
enabled: process.env.TEST_NOTIFY_GOG === '1',
delayMs: 1000,
title: 'gog',
games: [{ title: 'Haven Park', status: 'claimed', url: URL_CLAIM }],
},
];
if (false) { for (const scenario of scenarios) {
await delay(1000); if (!scenario.enabled) continue;
const notify_games = [ if (scenario.delayMs) await delay(scenario.delayMs);
{ title: 'Haven Park', status: 'claimed', url: URL_CLAIM }, await notify(`${scenario.title}:<br>${html_game_list(scenario.games)}`);
];
notify(`gog:<br>${html_game_list(notify_games)}`);
} }

View file

@ -0,0 +1,21 @@
// open issue: prevents handleSIGINT() to work if prompt is cancelled with Ctrl-C instead of Escape: https://github.com/enquirer/enquirer/issues/372
function onRawSIGINT(fn) {
const { stdin, stdout } = process;
stdin.setRawMode(true);
stdin.resume();
stdin.on('data', data => {
const key = data.toString('utf-8');
if (key === '\u0003') { // ctrl + c
fn();
} else {
stdout.write(key);
}
});
}
console.log(1);
onRawSIGINT(() => {
console.log('raw'); process.exit(1);
});
console.log(2);
// onRawSIGINT workaround for enquirer keeps the process from exiting here...

View file

@ -1,36 +1,14 @@
// https://github.com/enquirer/enquirer/issues/372 // https://github.com/enquirer/enquirer/issues/372
import { prompt } from '../util.js'; import { prompt, handleSIGINT } from '../src/util.js';
const handleSIGINT = () => process.on('SIGINT', () => { // e.g. when killed by Ctrl-C
console.log('\nInterrupted by SIGINT. Exit!');
process.exitCode = 130;
});
handleSIGINT(); handleSIGINT();
function onRawSIGINT(fn) {
const { stdin, stdout } = process;
stdin.setRawMode(true);
stdin.resume();
stdin.on('data', data => {
const key = data.toString('utf-8');
if (key === '\u0003') { // ctrl + c
fn();
} else {
stdout.write(key);
}
});
}
onRawSIGINT(() => {
console.log('raw'); process.exit(1);
});
console.log('hello'); console.log('hello');
console.error('hello error'); console.error('hello error');
try { try {
let i = 'foo'; const first = await prompt(); // SIGINT no longer handled if this is executed
i = await prompt(); // SIGINT no longer handled if this is executed const second = await prompt(); // SIGINT no longer handled if this is executed
// handleSIGINT(); console.log('values:', first, second);
console.log('value:', i);
setTimeout(() => console.log('timeout 3s'), 3000); setTimeout(() => console.log('timeout 3s'), 3000);
} catch (e) { } catch (e) {
process.exitCode ||= 1; process.exitCode ||= 1;

View file

@ -13,3 +13,8 @@ await enquirer.prompt({
name: 'username', name: 'username',
message: 'What is your username?', message: 'What is your username?',
}); });
await enquirer.prompt({
type: 'input',
name: 'username',
message: 'What is your username 2?',
});

View file

@ -1,10 +1,7 @@
// TODO This is mostly a copy of epic-games.js
// New assets to claim every first Tuesday of a month.
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
import { authenticator } from 'otplib'; import { authenticator } from 'otplib';
import path from 'path'; import path from 'node:path';
import { writeFileSync } from 'fs'; import { writeFileSync } from 'node:fs';
import { resolve, jsonDb, datetime, stealth, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js'; import { resolve, jsonDb, datetime, stealth, filenamify, prompt, notify, html_game_list, handleSIGINT } from './src/util.js';
import { cfg } from './src/config.js'; import { cfg } from './src/config.js';
@ -21,11 +18,10 @@ const db = await jsonDb('unrealengine.json', {});
const context = await firefox.launchPersistentContext(cfg.dir.browser, { const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless, headless: cfg.headless,
viewport: { width: cfg.width, height: cfg.height }, viewport: { width: cfg.width, height: cfg.height },
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36', // see replace of Headless in util.newStealthContext. TODO Windows UA enough to avoid 'device not supported'? update if browser is updated? userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.83 Safari/537.36', // Windows UA avoids "device not supported"; update when browser version changes
// userAgent for firefox: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0
locale: 'en-US', // ignore OS locale to be sure to have english text for locators locale: 'en-US', // ignore OS locale to be sure to have english text for locators
recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800 recordVideo: cfg.record ? { dir: 'data/record/', size: { width: cfg.width, height: cfg.height } } : undefined, // will record a .webm video for each page navigated; without size, video would be scaled down to fit 800x800
recordHar: cfg.record ? { path: `data/record/ue-${datetime()}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools recordHar: cfg.record ? { path: `data/record/ue-${filenamify(datetime())}.har` } : undefined, // will record a HAR file with network requests and responses; can be imported in Chrome devtools
handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved handleSIGINT: false, // have to handle ourselves and call context.close(), otherwise recordings from above won't be saved
}); });
@ -36,7 +32,7 @@ await stealth(context);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist const page = context.pages().length ? context.pages()[0] : await context.newPage(); // should always exist
// console.debug('userAgent:', await page.evaluate(() => navigator.userAgent)); await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaround for https://github.com/vogler/free-games-claimer/issues/277 until Playwright fixes it
const notify_games = []; const notify_games = [];
let user; let user;
@ -59,23 +55,32 @@ try {
const email = cfg.eg_email || await prompt({ message: 'Enter email' }); const email = cfg.eg_email || await prompt({ message: 'Enter email' });
const password = email && (cfg.eg_password || await prompt({ type: 'password', message: 'Enter password' })); const password = email && (cfg.eg_password || await prompt({ type: 'password', message: 'Enter password' }));
if (email && password) { if (email && password) {
// await page.click('text=Sign in with Epic Games');
await page.fill('#email', email); await page.fill('#email', email);
await page.click('button[type="submit"]'); await page.click('button[type="submit"]');
await page.fill('#password', password); await page.fill('#password', password);
await page.click('button[type="submit"]'); await page.click('button[type="submit"]');
page.waitForSelector('#h_captcha_challenge_login_prod iframe').then(() => { const watchCaptchaDuringLogin = async () => {
try {
await page.waitForSelector('#h_captcha_challenge_login_prod iframe', { timeout: 15000 });
console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.'); console.error('Got a captcha during login (likely due to too many attempts)! You may solve it in the browser, get a new IP or try again in a few hours.');
notify('unrealengine: got captcha during login. Please check.'); notify('unrealengine: got captcha during login. Please check.');
}).catch(_ => { }); } catch {
// handle MFA, but don't await it return;
page.waitForURL('**/id/login/mfa**').then(async () => { }
};
const watchMfa = async () => {
try {
await page.waitForURL('**/id/login/mfa**', { timeout: cfg.login_timeout });
console.log('Enter the security code to continue - This appears to be a new device, browser or location. A security code has been sent to your email address at ...'); console.log('Enter the security code to continue - This appears to be a new device, browser or location. A security code has been sent to your email address at ...');
// TODO locator for text (email or app?)
const otp = cfg.eg_otpkey && authenticator.generate(cfg.eg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them const otp = cfg.eg_otpkey && authenticator.generate(cfg.eg_otpkey) || await prompt({ type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!' }); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
await page.locator('input[name="code-input-0"]').pressSequentially(otp.toString()); await page.locator('input[name="code-input-0"]').pressSequentially(otp.toString());
await page.click('button[type="submit"]'); await page.click('button[type="submit"]');
}).catch(_ => { }); } catch {
return;
}
};
watchCaptchaDuringLogin();
watchMfa();
} else { } else {
console.log('Waiting for you to login in the browser.'); console.log('Waiting for you to login in the browser.');
await notify('unrealengine: no longer signed in and not enough options set for automatic login.'); await notify('unrealengine: no longer signed in and not enough options set for automatic login.');
@ -122,7 +127,7 @@ try {
} }
ids.push(id); ids.push(id);
} }
if (!ids.length) { if (ids.length === 0) {
console.log('Nothing to claim'); console.log('Nothing to claim');
} else { } else {
await page.waitForTimeout(2000); await page.waitForTimeout(2000);
@ -134,18 +139,22 @@ try {
notify('unrealengine: ' + err); notify('unrealengine: ' + err);
process.exit(1); process.exit(1);
} }
// await page.pause();
console.log('Click shopping cart'); console.log('Click shopping cart');
await page.locator('.shopping-cart').click(); await page.locator('.shopping-cart').click();
// await page.waitForTimeout(2000);
await page.locator('button.checkout').click(); await page.locator('button.checkout').click();
console.log('Click checkout'); console.log('Click checkout');
// maybe: Accept End User License Agreement // maybe: Accept End User License Agreement
page.locator('[name=accept-label]').check().then(() => { const acceptEulaIfPresent = async () => {
try {
await page.locator('[name=accept-label]').check({ timeout: 10000 });
console.log('Accept End User License Agreement'); console.log('Accept End User License Agreement');
page.locator('span:text-is("Accept")').click(); // otherwise matches 'Accept All Cookies' await page.locator('span:text-is("Accept")').click(); // otherwise matches 'Accept All Cookies'
}).catch(_ => { }); } catch {
await page.waitForSelector('#webPurchaseContainer iframe'); // TODO needed? return;
}
};
acceptEulaIfPresent();
await page.waitForSelector('#webPurchaseContainer iframe');
const iframe = page.frameLocator('#webPurchaseContainer iframe'); const iframe = page.frameLocator('#webPurchaseContainer iframe');
if (cfg.debug) await page.pause(); if (cfg.debug) await page.pause();
@ -160,14 +169,27 @@ try {
// I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872 // I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872
const btnAgree = iframe.locator('button:has-text("I Agree")'); const btnAgree = iframe.locator('button:has-text("I Agree")');
btnAgree.waitFor().then(() => btnAgree.click()).catch(_ => { }); // EU: wait for and click 'I Agree' const acceptIfRequired = async () => {
try {
await btnAgree.waitFor({ timeout: 10000 });
await btnAgree.click();
} catch {
return;
}
}; // EU: wait for and click 'I Agree'
acceptIfRequired();
try { try {
// context.setDefaultTimeout(100 * 1000); // give time to solve captcha, iframe goes blank after 60s? // context.setDefaultTimeout(100 * 1000); // give time to solve captcha, iframe goes blank after 60s?
const captcha = iframe.locator('#h_captcha_challenge_checkout_free_prod iframe'); const captcha = iframe.locator('#h_captcha_challenge_checkout_free_prod iframe');
captcha.waitFor().then(async () => { // don't await, since element may not be shown const watchCaptchaChallenge = async () => {
// console.info(' Got hcaptcha challenge! NopeCHA extension will likely solve it.') try {
await captcha.waitFor({ timeout: 10000 });
console.error(' Got hcaptcha challenge! Lost trust due to too many login attempts? You can solve the captcha in the browser or get a new IP address.'); console.error(' Got hcaptcha challenge! Lost trust due to too many login attempts? You can solve the captcha in the browser or get a new IP address.');
}).catch(_ => { }); // may time out if not shown } catch {
return;
}
}; // may time out if not shown
watchCaptchaChallenge();
await page.waitForSelector('text=Thank you'); await page.waitForSelector('text=Thank you');
for (const id of ids) { for (const id of ids) {
db.data[user][id].status = 'claimed'; db.data[user][id].status = 'claimed';
@ -175,16 +197,12 @@ try {
} }
notify_games.forEach(g => g.status == 'failed' && (g.status = 'claimed')); notify_games.forEach(g => g.status == 'failed' && (g.status = 'claimed'));
console.log('Claimed successfully!'); console.log('Claimed successfully!');
// context.setDefaultTimeout(cfg.timeout);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
// console.error(' Failed to claim! Try again if NopeCHA timed out. Click the extension to see if you ran out of credits (refill after 24h). To avoid captchas try to get a new IP or set a cookie from https://www.hcaptcha.com/accessibility');
console.error(' Failed to claim! To avoid captchas try to get a new IP address.'); console.error(' Failed to claim! To avoid captchas try to get a new IP address.');
await page.screenshot({ path: screenshot('failed', `${filenamify(datetime())}.png`), fullPage: true }); await page.screenshot({ path: screenshot('failed', `${filenamify(datetime())}.png`), fullPage: true });
// db.data[user][id].status = 'failed';
notify_games.forEach(g => g.status = 'failed'); notify_games.forEach(g => g.status = 'failed');
} }
// notify_game.status = db.data[user][game_id].status; // claimed or failed
if (notify_games.length) await page.screenshot({ path: screenshot(`${filenamify(datetime())}.png`), fullPage: false }); // fullPage is quite long... if (notify_games.length) await page.screenshot({ path: screenshot(`${filenamify(datetime())}.png`), fullPage: false }); // fullPage is quite long...
console.log('Done'); console.log('Done');

250
xbox.js
View file

@ -1,250 +0,0 @@
import { firefox } from 'playwright-firefox'; // stealth plugin needs no outdated playwright-extra
import { authenticator } from 'otplib';
import {
datetime,
handleSIGINT,
html_game_list,
jsonDb,
notify,
prompt,
} from './src/util.js';
import { cfg } from './src/config.js';
// ### SETUP
const URL_CLAIM = 'https://www.xbox.com/en-US/live/gold'; // #gameswithgold";
console.log(datetime(), 'started checking xbox');
const db = await jsonDb('xbox.json');
db.data ||= {};
handleSIGINT();
// https://playwright.dev/docs/auth#multi-factor-authentication
const context = await firefox.launchPersistentContext(cfg.dir.browser, {
headless: cfg.headless,
viewport: { width: cfg.width, height: cfg.height },
locale: 'en-US', // ignore OS locale to be sure to have english text for locators -> done via /en in URL
});
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
const page = context.pages().length
? context.pages()[0]
: await context.newPage(); // should always exist
const notify_games = [];
let user;
main();
async function main() {
try {
await performLogin();
await getAndSaveUser();
await redeemFreeGames();
} catch (error) {
console.error(error);
process.exitCode ||= 1;
if (error.message && process.exitCode != 130) notify(`xbox failed: ${error.message.split('\n')[0]}`);
} finally {
await db.write(); // write out json db
if (notify_games.filter(g => g.status != 'existed').length) {
// don't notify if all were already claimed
notify(`xbox (${user}):<br>${html_game_list(notify_games)}`);
}
await context.close();
}
}
async function performLogin() {
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' }); // default 'load' takes forever
const signInLocator = page
.getByRole('link', {
name: 'Sign in to your account',
})
.first();
const usernameLocator = page
.getByRole('button', {
name: 'Account manager for',
})
.first();
await Promise.any([signInLocator.waitFor(), usernameLocator.waitFor()]);
if (await usernameLocator.isVisible()) {
return; // logged in using saved cookie
} else if (await signInLocator.isVisible()) {
console.error('Not signed in anymore.');
await signInLocator.click();
await signInToXbox();
} else {
console.error('lost! where am i?');
}
}
async function signInToXbox() {
page.waitForLoadState('domcontentloaded');
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout); // give user some extra time to log in
console.info(`Login timeout is ${cfg.login_timeout / 1000} seconds!`);
// ### FETCH EMAIL/PASS
if (cfg.xbox_email && cfg.xbox_password) console.info('Using email and password from environment.');
else console.info(
'Press ESC to skip the prompts if you want to login in the browser (not possible in headless mode).',
);
const email = cfg.xbox_email || await prompt({ message: 'Enter email' });
const password =
email &&
(cfg.xbox_password ||
await prompt({
type: 'password',
message: 'Enter password',
}));
// ### FILL IN EMAIL/PASS
if (email && password) {
const usernameLocator = page
.getByPlaceholder('Email, phone, or Skype')
.first();
const passwordLocator = page.getByPlaceholder('Password').first();
await Promise.any([
usernameLocator.waitFor(),
passwordLocator.waitFor(),
]);
// username may already be saved from before, if so, skip to filling in password
if (await page.getByPlaceholder('Email, phone, or Skype').isVisible()) {
await usernameLocator.fill(email);
await page.getByRole('button', { name: 'Next' }).click();
}
await passwordLocator.fill(password);
await page.getByRole('button', { name: 'Sign in' }).click();
// handle MFA, but don't await it
page.locator('input[name="otc"]')
.waitFor()
.then(async () => {
console.log('Two-Step Verification - Enter security code');
console.log(
await page
.locator('div[data-bind="text: description"]')
.innerText(),
);
const otp =
cfg.xbox_otpkey &&
authenticator.generate(cfg.xbox_otpkey) ||
await prompt({
type: 'text',
message: 'Enter two-factor sign in code',
validate: n => n.toString().length == 6 ||
'The code must be 6 digits!',
}); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
await page.type('input[name="otc"]', otp.toString());
await page
.getByLabel('Don\'t ask me again on this device')
.check(); // Trust this Browser
await page.getByRole('button', { name: 'Verify' }).click();
})
.catch(_ => {});
// Trust this browser, but don't await it
page.getByLabel('Don\'t show this again')
.waitFor()
.then(async () => {
await page.getByLabel('Don\'t show this again').check();
await page.getByRole('button', { name: 'Yes' }).click();
})
.catch(_ => {});
} else {
console.log('Waiting for you to login in the browser.');
await notify(
'xbox: no longer signed in and not enough options set for automatic login.',
);
if (cfg.headless) {
console.log(
'Run `SHOW=1 node xbox` to login in the opened browser.',
);
await context.close();
process.exit(1);
}
}
// ### VERIFY SIGNED IN
await page.waitForURL(`${URL_CLAIM}**`);
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
}
async function getAndSaveUser() {
user = await page.locator('#mectrl_currentAccount_primary').innerHTML();
console.log(`Signed in as '${user}'`);
db.data[user] ||= {};
}
async function redeemFreeGames() {
const monthlyGamesLocator = await page.locator('.f-size-large').all();
const monthlyGamesPageLinks = await Promise.all(
monthlyGamesLocator.map(
async el => await el.locator('a').getAttribute('href'),
),
);
console.log('Free games:', monthlyGamesPageLinks);
for (const url of monthlyGamesPageLinks) {
await page.goto(url);
const title = await page.locator('h1').first().innerText();
const game_id = page.url().split('/').pop();
db.data[user][game_id] ||= { title, time: datetime(), url: page.url() }; // this will be set on the initial run only!
console.log('Current free game:', title);
const notify_game = { title, url, status: 'failed' };
notify_games.push(notify_game); // status is updated below
// SELECTORS
const getBtnLocator = page.getByText('GET', { exact: true }).first();
const installToLocator = page
.getByText('INSTALL TO', { exact: true })
.first();
await Promise.any([
getBtnLocator.waitFor(),
installToLocator.waitFor(),
]);
if (await installToLocator.isVisible()) {
console.log(' Already in library! Nothing to claim.');
notify_game.status = 'existed';
db.data[user][game_id].status ||= 'existed'; // does not overwrite claimed or failed
} else if (await getBtnLocator.isVisible()) {
console.log(' Not in library yet! Click GET.');
await getBtnLocator.click();
// wait for popup
await page
.locator('iframe[name="purchase-sdk-hosted-iframe"]')
.waitFor();
const popupLocator = page.frameLocator(
'[name=purchase-sdk-hosted-iframe]',
);
const finalGetBtnLocator = popupLocator.getByText('GET');
await finalGetBtnLocator.waitFor();
await finalGetBtnLocator.click();
await page.getByText('Thank you for your purchase.').waitFor();
notify_game.status = 'claimed';
db.data[user][game_id].status = 'claimed';
db.data[user][game_id].time = datetime(); // claimed time overwrites failed/dryrun time
console.log(' Claimed successfully!');
}
// notify_game.status = db.data[user][game_id].status; // claimed or failed
// const p = path.resolve(cfg.dir.screenshots, playstation-plus', `${game_id}.png`);
// if (!existsSync(p)) await page.screenshot({ path: p, fullPage: false }); // fullPage is quite long...
}
}