Error with script taking screenshot: 'globalThis.btoa is not a function'

This topic was automatically generated from Slack. You can find the original thread here.

Hello! I’m using a simple script to take a screenshot using browserless, where it loads the page, selects an element on the page and takes the screenshot of just that element’s area.

Until then, it was working correctly, now I started getting the following error: Waiting for selector 'selector' failed: globalThis.btoa is not a function.

when i text the code in the browserless debbuger, the code works correctly
Does anyone have any idea what it could be?

the selector in question would be: body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--center
page: Live stock, index, futures, Forex and Bitcoin charts on TradingView

Hello! I’m using a simple script to take a screenshot using browserless, where it loads the page, selects an element on the page and takes the screenshot of just that element’s area.

Until then, it was working correctly, now I started getting the following error: Waiting for selector 'selector' failed: globalThis.btoa is not a function.

when i text the code in the browserless debbuger, the code works correctly
Does anyone have any idea what it could be?

the selector in question would be: body > div.js-rootresizer__contents.layout-with-border-radius > div.layout__area--center
page: Live stock, index, futures, Forex and Bitcoin charts on TradingView

I understand that you’re encountering an issue with your script when using browserless to take a screenshot of a specific element. The error you’re experiencing is related to the globalThis.btoa function not being available. It’s possible that the environment in which your script is running might not have the btoa function available. To resolve this issue, you can try adding a polyfill for the btoa function in your script. Here’s an example of how you can define the btoa function if it’s not available: if (typeof globalThis.btoa === "undefined") { globalThis.btoa = function (str) { return Buffer.from(str, "binary").toString("base64"); }; } Add this code snippet at the beginning of your script, and it should define the btoa function if it’s not already available in the environment. If you still encounter issues, please provide more information about your script, such as the code you’re using, so I can better understand the problem and help you find a solution.

Wow, it’s an AI? Worked perfectly. Simple and quick solution. Thanks!

I just don’t understand why I got this error just now, I’ve been using this code since January

likely they shipped a change to some core package, we’ll update the packages to the latest version on new deploys

Ok, Thanks!