Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Provide require() in JS functions #19

Open
nesk opened this issue Mar 25, 2019 · 4 comments
Open

Provide require() in JS functions #19

nesk opened this issue Mar 25, 2019 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@nesk
Copy link
Member

nesk commented Mar 25, 2019

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

@fengerwoo
Copy link

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

@fengerwoo
Copy link

page call failed

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

@nesk nesk added the good first issue Good for newcomers label Sep 21, 2020
@popouille
Copy link

Hello,
any news?

@sngrl
Copy link

sngrl commented Aug 3, 2021

Good day, any changes?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants