Describe the bug
eval
function is not working as expected on the latest browserless
images as it can't access the current context.
The problem is that our system (a +300 pods kubernetes cluster) heavily depends on eval
function to execute user code and expose very specific variables as context that were generated by a very complex "base" function we designed. However, it seems the latest browserless
versions seems to use vm2
npm module to mock and sandbox the eval
function completely blocking any attempt to send a context which breaks our system function.
To Reproduce
Steps to reproduce the behavior using a ruby script:
docker run --rm -p 3000:3000 browserless/chrome:1-puppeteer-13.5.2
typhoeus
gem for testing the request: gem install typhoeus
require 'json'
require 'typhoeus'
body = {
context: {},
code: '
module.exports = async ({ browser, page, context }) => {
var my_var = "Hello"
const data = eval("my_var")
return {
data: data,
type: "application/json",
}
}
'
}
req = Typhoeus::Request.new(
"http://127.0.0.1:3000/function/",
headers: {'Content-Type' => 'application/json'},
method: :post,
body: JSON.generate(body),
timeout: 120
)
puts req.run.body
Expected behavior
eval
gets access to my_var
and displays "Hello!" in the terminal.
Desktop (please complete the following information):
Additional context
We are currently using a very old image that is working fine: browserless/chrome:1.42.0-puppeteer-5.4.1
We use vm2 to execute custom code. It's a known issue that, unfortunately, direct eval()
calls don't work on vm2.
I you really need eval, by default, custom code doesn't run in strict mode, so you can declare the vars globally and access them via eval()
:
module.exports = async () => {
my_var = `Hello`;
const data = eval(`my_var`);
return { data: data, type: `application/json` };
};
Owner Name | browserless |
Repo Name | chrome |
Full Name | browserless/chrome |
Language | TypeScript |
Created Date | 2017-11-17 |
Updated Date | 2023-03-22 |
Star Count | 5309 |
Watcher Count | 47 |
Fork Count | 516 |
Issue Count | 29 |
Issue Title | Created Date | Updated Date |
---|