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

fix(plugin-recaptcha): Enhance esbuild transpilation support of content scripts #763

Merged
merged 1 commit into from
Feb 27, 2023

Conversation

transitive-bullshit
Copy link
Contributor

This PR builds on #758

It also fixes a fix to workaround esbuild's __name semantics: privatenumber/tsx#113

The author of esbuild recommends against calling toString() on a function or class as this library is doing and instead creating a separate build for these entrypoints. This results in a lot more deterministic functionality, but that would also involve a larger PR.

So for now, this is the minimal amount of code changes to get puppeteer-extra-plugin-recaptcha's injected content scripts to work when used in an application that's compiled using esbuild.

I ran into this issue while building the chatgpt node.js wrapper, which uses uses tsx to transpile TS to JS on-the-fly (using esbuild under the hood).

Also just wanted to say hey @berstend 👋 I remember working with you a bit years ago back in the early days of this project. Really really impressive to see how far it's come 🔥

Thanks for all your hard work && cheers,
-- Travis

@github-actions github-actions bot added plugin: puppeteer-extra PuppeteerExtra Plugin related plugin: recaptcha 🏴 reCAPTCHA plugin related labels Dec 18, 2022
Comment on lines +75 to +79
// Some bundlers transform classes to anonymous classes that are assigned to
// vars (e.g. esbuild). In such cases, `unexpected token '{'` errors are thrown
// once the script is executed. Let's bring class name back to script in such
// cases!
scriptSource = scriptSource.replace(/class \{/, `class ${scriptName} {`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey 👋

Mind co-authoring these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @igalklebanov yeah; for sure, I'd like to give you credit. Do I need to rebase on top of your branch as a remote or something? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that simply re-comitting (remove -> add) just those lines with co-author commit message body will do. I'll close my PR once its done. Your description describes the problem better.

@berstend
Copy link
Owner

Hey @transitive-bullshit 😄👋 your early feedback was instrumental to make this project fly, thanks again :)

I'll merge this PR (thanks!) in after #758 from @igalklebanov to help with the attribution

@berstend berstend changed the title fix: esbuild issue with eval'ed content scripts and __name fix(plugin-recaptcha): Enhance esbuild transpilation support of content scripts Feb 27, 2023
@berstend berstend merged commit 8ad9ea4 into berstend:master Feb 27, 2023
@berstend
Copy link
Owner

berstend commented Mar 1, 2023

Successfully published:
 - [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: puppeteer-extra PuppeteerExtra Plugin related plugin: recaptcha 🏴 reCAPTCHA plugin related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants