rialto-php / rialto

Manage Node resources with PHP
MIT License
170 stars 80 forks source link

Support passing Node resources in JS function scopes #3

Closed nesk closed 6 years ago

nesk commented 6 years ago

Currently, it is not possible to provide a Node resource in JS function scopes, like this:

$page = (new Puppeteer)->launch()->newPage();

$page->on(
    'domcontentloaded',
    JsFunction::create('page.content().then(console.log)', ['page' => $page])
);

This could be done by storing the required resources in Node's global object. The above function creation would generate the following JS code:

return function () {
    var page = global.puphpeteerResources['a-unique-id-to-the-resource'];
    page.content().then(console.log);
};

Original idea from nesk/puphpeteer#9 by @john-f-chamberlain