diff --git a/CHANGELOG.md b/CHANGELOG.md index dbe90cdf..0db0f89f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ ## 0.3.0 -> *20xx-xx-xx* (not released) +> *2018-08-13* > Make a crawl instance sharable among multiple scripts diff --git a/examples/persistent-browser.php b/examples/persistent-browser.php new file mode 100644 index 00000000..07deffc9 --- /dev/null +++ b/examples/persistent-browser.php @@ -0,0 +1,50 @@ + 'php://stdout' + ]); + } catch (\HeadlessChromium\Exception\BrowserConnectionFailed $e) { + // The browser was probably closed + // Keep $browser null and start it again bellow + } +} + +// if $browser is null then create a new chrome instance +if (!$browser) { + $factory = new \HeadlessChromium\BrowserFactory(); + $browser = $factory->createBrowser([ + 'headless' => false, + 'keepAlive' => true + ]); + + // save the uri to be able to connect again to browser + file_put_contents($socketFile, $browser->getSocketUri()); +} + +// do something with the browser +$page = $browser->createPage(); + +$page->navigate('http://example.com')->waitForNavigation(); \ No newline at end of file