diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 105a097b..3545bc90 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -282,3 +282,15 @@ AWS Lambda [limits](https://docs.aws.amazon.com/lambda/latest/dg/limits.html) de - https://github.com/adieuadieu/serverless-chrome/blob/master/docs/chrome.md (tracks the latest Chromium snapshots) - https://github.com/universalbasket/aws-lambda-chrome - https://github.com/Kikobeats/aws-lambda-chrome + +## Code Transpilation Issues + +If you are using a JavaScript transpiler like babel or TypeScript, calling `evaluate()` with an async function might not work. This is because while `puppeteer` uses `Function.prototype.toString()` to serialize functions while transpilers could be changing the output code in such a way it's incompatible with `puppeteer`. + +Some workarounds to this problem would be to instruct the transpiler not to mess up with the code, for example, configure TypeScript to use latest ecma version (`"target": "es2018"`). Another workaround could be using string templates instead of functions: + +```js +await page.evaluate(`(async() => { + console.log('1'); +})()`); +```