Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Attempt to fix the problem of the extension working in the background #88

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Serega007RU
Copy link

@Serega007RU Serega007RU commented Oct 1, 2023

Hello! In this Pull Request, I will try to fix the problems of the extension working in the background when the tab on which the extension solves the captcha is not focused.

I will explain for the code. The solution to this problem was based on the code from here https://github.com/turuslan/HackTimer Unfortunately, I can't find a more normal solution to this problem, Chrome does not allow the normal use of setInterval and setTimeout if the tab is not focused. It's a pretty rough decision to use a background expansion process, but it seems to be the only solution.

This PR is still a draft since I can't properly test my code. I do not know why, but after build I get this error in the console.
image
The extension from the Chrome Web Store works fine. That is, there is something wrong in my assembly or I am somehow assembling it wrong. Help me solve this problem to test my changes.

@Wikidepia
Copy link
Owner

This PR is still a draft since I can't properly test my code. I do not know why, but after build I get this error in the console.

You might need to update onnxruntime from https://github.com/Wikidepia/hektCaptcha-onnxruntime-web.

It seems that hacktimer is not updated regularly, and I found worker-timers (https://github.com/chrisguttandin/worker-timers) which seems to be updated more frequently and can be imported. Can you try it?

@Serega007RU
Copy link
Author

You might need to update onnxruntime from https://github.com/Wikidepia/hektCaptcha-onnxruntime-web.

How should I do this? Should I write command npm update onnxruntime-web? I tried, he writes me "up to date"

I'm bad at Node Js, so such simple things can be difficult for me, sorry, I'm only good at JavaScript and Chrome Extension API

@Wikidepia
Copy link
Owner

Hmm, I guess I forgot to push it, will check it later

@Serega007RU
Copy link
Author

Serega007RU commented Oct 2, 2023

I managed to get rid of this error. In the package-lock.json file in "onnxruntime-web" in "resolved" I changed the commit number to the last one that you have on GitHub.

Regarding the worker-timers, it really looks better. You can try to just use this project without changes, but it will create a Serivece Worker for each Content Script. Here in the screenshot you can see 6 Service Workers that worker-timers created, and there is only 1 captcha on the page.
image
It seems to me that this is wrong and quite resource-intensive, and it will have a bad effect on performance if the user wants to solve many captchas at the same time.
In this PR, I actually did what HackTimer redid the Service Worker, instead of constantly creating it, I used an existing Service Worker in the Background Chrome Extension. worker-timers looks more complicated and I don't have enough knowledge of NodeJS to redo it for Chrome Extension.

I also found https://github.com/chrisguttandin/worker-timers-mock, it doesn't seem to use Service Worker, I'll try to test it later.

I will still think about solving this problem

If you have any other thoughts on this problem, tell me.

@Wikidepia
Copy link
Owner

Wikidepia commented Oct 2, 2023

I guess this is the best answer for now, can you run npm run format to this PR and remove the test & console.log

@Serega007RU
Copy link
Author

Are you sure that the choice with HackTimer will do?
I will still try with worker-timers, create an issue to the author with a proposal to add support for Chrome Extension in order to optimize the use of Service Worker.
I am interested in this because my project (extension) also has this problem.

@Fer010
Copy link

Fer010 commented Oct 3, 2023

If I may jump in here... @Serega007RU would you mind sharing with me some specifics of the problem? I would really like to help with this extension.
I understand it's having problems solving when the tab is not focused, but I don't fully get the setInterval/setTimeout relation to this particular issue, although I like how worker-timers might be able to workaround that particular limitation.
Anyway, could you explain me what made you conclude that setInterval/setTimeout are causing the solving problems in background tabs? That's actually what I'm not seeing right now.

Thanks!

@Serega007RU
Copy link
Author

Anyway, could you explain me what made you conclude that setInterval/setTimeout are causing the solving problems in background tabs? That's actually what I'm not seeing right now.

I explained it in more detail here #53
honestly, you have questioned me a little that hektCaptcha does not work in the background only because of problems with setTimeout and setInterval, I tested it only a few times, I will test it in more detail later, I will leave the computer for a few hours and check if it can pass more than 100 captchas in the background without my presence with the applied with the HackTimer patch

@Fer010
Copy link

Fer010 commented Oct 4, 2023

Don't get me wrong, I think your proposed solution with HackTimer might work.
I'm not facing the problem you described right now, but I'm using Tab Revolver extension to crawl the tabs in the window so that's probably the reason why I'm not getting it.

What I'm wondering is if the problem is related to setInterval/setTimeout, or the extension/background/service worker becoming inactive. In case of the later, maybe using a keep-alive solution (just pinging background.js with .sendMessage from the active tab, something like that) might do the trick. But it will require targeting ":///*" in host_permissions.

In case your current tests with HackTimer doesn't work as expected, let me know and I'll try to add a keep alive alternative for testing.

@Serega007RU
Copy link
Author

Tab Revolver

please give me a link, I can't find this extension by this name

@Serega007RU
Copy link
Author

Well, I tested it, it works. I mainly checked on reCAPTCHA, but this captcha reacts very badly if the tab is not active, it looks like Google is tracking it. A little disappointed with the result, I still have to keep the tab active.

@Serega007RU Serega007RU marked this pull request as ready for review October 4, 2023 22:42
@Wikidepia
Copy link
Owner

Well, I tested it, it works.

Did you test the tab revolver or this fix?

@Serega007RU
Copy link
Author

Did you test the tab revolver or this fix?

this extension doesn't fix anything, it just switches tabs one by one at a given time (every 30 seconds by default)

@Wikidepia
Copy link
Owner

I think this is ready to merge? Do you have any test / things to add? @Serega007RU

@Serega007RU
Copy link
Author

I think we should wait for a response from the author of worker-timers in chrisguttandin/worker-timers#434. Perhaps we could have missed a better solution to this problem

@Serega007RU
Copy link
Author

Well, it looks like worker-timers should be rewritten for Chrome Extensions so that it works with the background page of the extension. I have no desire to do this.
Then it's up to you to decide to accept this PR or try another option.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants