TheNetsky / Microsoft-Rewards-Script

Automated Microsoft Rewards script, using TypeScript, Cheerio and Playwright.
133 stars 33 forks source link

browserContext.newPage: Target page, context or browser has been closed #102

Closed PororoManon closed 1 month ago

PororoManon commented 2 months ago

I run this on my 2 machine, Linux Armbian and Windows 11. I got error from Linux Armbian, this my uname -a = Linux armbian 6.1.87-ophub aarch64 aarch64 aarch64 GNU/Linux. I never got this error before, I've used this script for 3 months on my Armbian machine.

npm run start
microsoft-rewards-script@1.4.5 start
node ./dist/index.js
[4/30/2024, 10:58:20 AM] [PID: 10960] [LOG] [MAIN] Bot started with 1 clusters
[4/30/2024, 10:58:20 AM] [PID: 10960] [LOG] [MAIN-WORKER] Started tasks for account myemail@gmail.com
[4/30/2024, 10:58:23 AM] [PID: 10960] [LOG] [BROWSER] Created browser with User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^
browserContext.newPage: Target page, context or browser has been closed
    at MicrosoftRewardsBot.Desktop (/home/Microsoft-Rewards-Script/dist/index.js:100:39)
    at async MicrosoftRewardsBot.runTasks (/home/Microsoft-Rewards-Script/dist/index.js:83:13)

edit: I sent script on my windows 11 which is success, but still show that error. I git clone and setup it again--change config, account--but still got error.

PororoManon commented 2 months ago

hi, i just wanna to update. I got same error but from different state(?) i think. After all searches done, it should show 'destroy all workers', but it shows error like this.

image

serzak51 commented 2 months ago

This error happens when the browser get closed. Do not close the chromium instances, else this error will pop-up. If you are not, check if there is a background script who sometimes kill chromium for some reason. Else there's something that make chromium crash. Try to reinstall playwright, maybe something got corrupted in your chromium

PororoManon commented 2 months ago

check if there is a background script who sometimes kill chromium for some reason

Hi, I know this sound stupid question. Can you teach me how to know how to do this? I've try search it on google, and I cant find command that let me know who killed my chromium or nodejs process. Thanks in advance! :D

serzak51 commented 2 months ago

There isn't really a command for it, maybe with the computer log, but it would take forever. Generally programs doesn't kill other program, because if everyone start to do that, it gets messy pretty fast. Just try to remember if you made a script that at some point might kill chromium. If there is one, check that it doesn't interfere with the chromium instances that you don't want to be killed. If you don't remember making one like that, then it's probably not the issue, probably more chromium who decide to crash

PororoManon commented 2 months ago

I do not install or run any script on my PC, Im pretty sure about this. I only install CasaOS with sonarr, radarr, deluge, and jackett. I don't know this would affect chromium instance or not.

I've tried download chromium binaries, and use launchOptions: { executablePath: '/root/chrome-linux/chrome' }, but still failed.

PororoManon commented 2 months ago

Hi! i just want to update my issue. I downgrade playwright to 1.42.0 and run it. Then, it shows another error, I think with same problem (chromium closed before the process complete). Here's the error log.

before, I use playwright version 1.43.0

[5/6/2024, 12:14:34 PM] [PID: 572741] [LOG] [MAIN] Starting DESKTOP browser
[5/6/2024, 12:14:38 PM] [PID: 572741] [ERROR] [LOGIN] An error occurred:Error: page.goto: Target page, context or browser has been closed
Call log:
  - navigating to "https://rewards.bing.com/signin", waiting until "load"

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "undefined".] {
  code: 'ERR_UNHANDLED_REJECTION'
}
TrinitroToluen0 commented 2 months ago

This happens to me everyday, idk if there is a solution, i just restart the script ever and ever, i've been thinking about making a script that automatically restarts this script if an error happens or the workers decrease a lot

serzak51 commented 2 months ago

I just thought about it, it's not impossible that your connection block bing, resulting in a blank page that the script doesn't understand. Try to see if you can use bing on a regular browser. If not, you can try to change your dns, and if it doesn't bring back bing, you will need to change connection You can also try with the new version to increase timeout. I don't think it comes from here, because it would give a timeout error, but maybe it can help

PororoManon commented 2 months ago

Sorry for super late response.

I just thought about it, it's not impossible that your connection block bing, resulting in a blank page that the script doesn't understand

I use Bing as my primary search engine, and I don't think my connection blocks it.

You can also try with the new version to increase timeout

I changed the timeout from 10000ms to 30000ms, but I'm still getting an error instantly. It seems like it's not even waiting for 30000ms.

I'm now using Docker to run this script, and everything is working very well.

PororoManon commented 2 months ago

after a few weeks use docker to run this script. my curiosity try run this script on machine instead docker. Its work. I change nothing on this script after deploying it on container.