Skip to content

How to render site with V8JS? #413

@grandemestre

Description

@grandemestre

I'm trying to understand how V8JS works, I did a test but it did not work.

I would like to render this site https://react.rocks/ to then use the DOMDocument.

So I did this:

$url = 'https://react.rocks/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,  true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$file = curl_exec($ch);

$dom = new DOMDocument;
$dom->loadHTML($file);
$v8 = new V8Js();

foreach( $dom->getElementsByTagName('script') as $script){

	$v8->executeString($script->nodeValue);
}
$exec = file_get_contents('https://react.rocks/scripts/bundle.js');
$v8->executeString($exec);

echo $file;

I've had this return

Uncaught exception 'V8JsScriptException' with message 'V8Js::compileString():2: ReferenceError: window is not defined' in info.php:18 Stack trace: #0 info.php(18): V8Js->executeString('var z={accessTo...') #1 {main} thrown in

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions