rialto icon indicating copy to clipboard operation
rialto copied to clipboard

Provide require() in JS functions

Open nesk opened this issue 6 years ago • 4 comments

The following JS function will throw an error with the message "require is not defined":

JsFunction::createWithBody("require('fs')");

This is because JS functions in PuPHPeteer are created with the Function constructor, the body of those functions don't have access to the module scope, but only to the global one.

The require() function could be provided by Rialto to JS function when unserializing them:

https://github.com/nesk/rialto/blob/2403adc6b5f8fd4114d1ec00d9cce2e6ce3a5656/src/node-process/Data/Unserializer.js#L89-L94

nesk avatar Mar 25 '19 13:03 nesk

How to use it? Please give an example of the encoding of instantiation \Nesk\Rialto\Data\JsFunction

fengerwoo avatar Mar 31 '20 10:03 fengerwoo

page call failed

$page->on('response', new \Nesk\Rialto\Data\JsFunction(["response"],
<<<JS
    page.evaluate(function(){
       document.createTextNode(JSON.stringify(response));
    })
JS
     ,['page']));

fengerwoo avatar Mar 31 '20 10:03 fengerwoo

Hello, any news?

popouille avatar Jun 06 '21 22:06 popouille

Good day, any changes?

sngrl avatar Aug 03 '21 17:08 sngrl