Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily disable/enable "automation build" Extension #46

Open
StigP1337 opened this issue May 24, 2024 · 7 comments
Open

Temporarily disable/enable "automation build" Extension #46

StigP1337 opened this issue May 24, 2024 · 7 comments

Comments

@StigP1337
Copy link

I am currently using the "automation build" Version of the Extension. Is there a way to temporarily disable the Extension from my Python Selenium script when captcha solving is not needed or not wanted?

With the "graphical build" Version I could use the Magic URL (https://nopecha.com/setup#enabled=false) to disable and enable the extension from my script when I need too.

This doesn't work in the "automation build" Version. Is their another way to achieve the same behaviour with this version? Or do you have plans to add such a feature?

Other extensions offer the possibility to use Javascript to change settings or to turn it off/on. Maybe you can add such a way to your extension?

@j-w-yun
Copy link
Collaborator

j-w-yun commented May 24, 2024

You're right, the graphical build has a way to export settings encoded as a URL - see documentation.

However, this URL will not work in the automation build. The reason for this is because settings are imported via manifest.json and the extension cannot write to it.

It would be useful to understand why you need this feature. For example, if you want to the extension to not run on certain pages, you can add the URL of the page to ignore in the disabled_hosts property of the manifest settings.

@StigP1337
Copy link
Author

One example is when I need to solve a captcha to submit a form and I am only interessted in the error feedback. I don't need to solve the captcha again when the form with error messages is displayed again.

@jakeee51
Copy link

jakeee51 commented Jun 9, 2024

I agree with @StigP1337 , such a feature to change settings on the fly would be useful. Although my issue is a bit different I felt it's similar enough to keep it in this post.

I'd like to be able to use the Magic URL in the automation build to update which nopecha key to use when one key runs out of credits.

I did notice the "keys": [] field in the manifest.json but I couldn't get it to work. I probably just don't understand its functionality fully.

@Le0Developer
Copy link
Collaborator

The keys field lets you round-robin across all keys in the array (it randomly picks one everytime it does a request)
The UI/extension popup always uses the key field, so some confusion might be caused by that.

keys is a band-aid solution until we have proper "multi-key" server-side.

@jakeee51
Copy link

jakeee51 commented Jun 9, 2024

Thanks @Le0Developer , looking forward to that multi-key support.

In the meantime perhaps @StigP1337 can use the solution I discovered. In order to disable the autmation build version of the extension without closing your selenium browser session you can use driver.execute_script() method which lets you execute JavaScript code in the browser.

For example:

def re_enable_nopecha_ext(driver):
      driver.get('chrome://extensions/'); time.sleep(1) 
      # Enable Developer mode using JavaScript
      driver.execute_script(
         'document.querySelector("extensions-manager").shadowRoot.querySelector("extensions-toolbar").shadowRoot.querySelector("#devMode").click()')
      time.sleep(1)

      # Construct the JavaScript command to click the enable/disable toggle button
      disable_script = f"""
      var manager = document.querySelector("extensions-manager").shadowRoot;
      var item = manager.querySelector('extensions-item-list').shadowRoot.querySelector('extensions-item[id="{nopecha_extension_id}"]').shadowRoot;
      item.querySelector('cr-toggle[aria-label="On, extension enabled"]').click();
      """
      enable_script = f"""
      var manager = document.querySelector("extensions-manager").shadowRoot;
      var item = manager.querySelector('extensions-item-list').shadowRoot.querySelector('extensions-item[id="{nopecha_extension_id}"]').shadowRoot;
      item.querySelector('cr-toggle[aria-label="Off"]').click();
      """
      driver.execute_script(disable_script)
      time.sleep(1)
      driver.execute_script(enable_script)
      print("Extension reloaded")

For my own project I edit the manifest.json then click the reload extension button.

@Le0Developer
Copy link
Collaborator

Or alternatively disable auto-open and open the captcha yourself.

@StigP1337
Copy link
Author

Thank you @jakeee51 and @Le0Developer for the replies. I will try the suggested solutions.

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

No branches or pull requests

4 participants