aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/WebDriverAbstract.php141
1 files changed, 141 insertions, 0 deletions
diff --git a/lib/WebDriverAbstract.php b/lib/WebDriverAbstract.php
new file mode 100644
index 00000000..db2fb7b1
--- /dev/null
+++ b/lib/WebDriverAbstract.php
@@ -0,0 +1,141 @@
+<?php
+
+use Facebook\WebDriver\Chrome\ChromeOptions;
+use Facebook\WebDriver\Remote\DesiredCapabilities;
+use Facebook\WebDriver\Remote\RemoteWebDriver;
+use Facebook\WebDriver\WebDriverCapabilities;
+
+/**
+ * An alternative abstract class for bridges depending on webdriver
+ *
+ * This class is meant a solution for active websites that use
+ * XMLHttpRequest (XHR) to load content and/or use JavaScript to
+ * change content. This class depends on a working webdriver setup.
+ */
+abstract class WebDriverAbstract extends BridgeAbstract
+{
+ /**
+ * Holds the remote webdriver object, including configuration and
+ * connection.
+ *
+ * @var RemoteWebDriver
+ */
+ protected RemoteWebDriver $driver;
+
+ /**
+ * Holds the uri of the feed's icon.
+ *
+ * @var string | null
+ */
+ private $feedIcon;
+
+ /**
+ * Returns the webdriver object.
+ *
+ * @return RemoteWebDriver
+ */
+ protected function getDriver(): RemoteWebDriver
+ {
+ return $this->driver;
+ }
+
+ /**
+ * Returns the uri of the feed's icon.
+ *
+ * @return string
+ */
+ public function getIcon()
+ {
+ return $this->feedIcon ?: parent::getIcon();
+ }
+
+ /**
+ * Sets the uri of the feed's icon.
+ *
+ * @param $iconurl string
+ */
+ protected function setIcon($iconurl)
+ {
+ $this->feedIcon = $iconurl;
+ }
+
+ /**
+ * Returns the ChromeOptions object.
+ *
+ * If the configuration parameter 'headless' is set to true, the
+ * argument '--headless' is added. Override this to change or add
+ * more options.
+ *
+ * @return ChromeOptions
+ */
+ protected function getBrowserOptions()
+ {
+ $chromeOptions = new ChromeOptions();
+ if (Configuration::getConfig('webdriver', 'headless')) {
+ $chromeOptions->addArguments(['--headless']); // --window-size=1024,1024
+ }
+ return $chromeOptions;
+ }
+
+ /**
+ * Returns the DesiredCapabilities object for the Chrome browser.
+ *
+ * The Chrome options are added. Override this to change or add
+ * more capabilities.
+ *
+ * @return WebDriverCapabilities
+ */
+ protected function getDesiredCapabilities(): WebDriverCapabilities
+ {
+ $desiredCapabilities = DesiredCapabilities::chrome();
+ $desiredCapabilities->setCapability(ChromeOptions::CAPABILITY, $this->getBrowserOptions());
+ return $desiredCapabilities;
+ }
+
+ /**
+ * Constructs the remote webdriver with the url of the remote (Selenium)
+ * webdriver server and the desired capabilities.
+ *
+ * This should be called in collectData() first.
+ */
+ protected function prepareWebDriver()
+ {
+ $server = Configuration::getConfig('webdriver', 'selenium_server_url');
+ $this->driver = RemoteWebDriver::create($server, $this->getDesiredCapabilities());
+ }
+
+ /**
+ * Maximizes the remote browser window (often important for reactive sites
+ * which change their appearance depending on the window size) and opens
+ * the uri set in the constant URI.
+ */
+ protected function prepareWindow()
+ {
+ $this->getDriver()->manage()->window()->maximize();
+ $this->getDriver()->get($this->getURI());
+ }
+
+ /**
+ * Closes the remote browser window and shuts down the remote webdriver
+ * connection.
+ *
+ * This must be called at the end of scraping, for example within a
+ * 'finally' block.
+ */
+ protected function cleanUp()
+ {
+ $this->getDriver()->quit();
+ }
+
+ /**
+ * Do your web scraping here and fill the $items array.
+ *
+ * Override this but call parent() first.
+ * Don't forget to call cleanUp() at the end.
+ */
+ public function collectData()
+ {
+ $this->prepareWebDriver();
+ $this->prepareWindow();
+ }
+} \ No newline at end of file
Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/bench/websocket-server/chat-server.bun.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-04-06fix(node:events): fix abort behaviorGravatar Derrick Farris 3-170/+177
2023-04-06test(node:events): remove `console.log`Gravatar Derrick Farris 1-1/+0
2023-04-06feat(node:events): finish `EE.AsyncIterator` and `node:events.on()`, add some...Gravatar Derrick Farris 5-369/+276
2023-04-06wip(node:events): get async iter working, work through test flakinessGravatar Derrick Farris 5-236/+328
2023-04-06wip(node:events): fix `node:events.on` async iter to specGravatar Derrick Farris 16-136/+1116
2023-04-06docs: add a section on uninstalling bun (#2560)Gravatar dave caruso 1-0/+8
2023-04-06docs(cli/bunx): add notice (#2574)Gravatar Jozef Steinhübl 1-0/+4
2023-04-06Fix `toEqual` when the second array has extra array holes (#2580)Gravatar Dylan Conway 3-18/+76
2023-04-06Add last modify field "mtime" for FileBlob (#1431) (#2491)Gravatar Zhongwei Yao 6-33/+128
2023-04-06bun-types: infer strict `Subprocess` from `Bun.spawn()` options, part 2 (#2573)Gravatar dave caruso 9-67/+165
2023-04-06cache needs to update, move to another process (#2578)Gravatar Dylan Conway 2-156/+171
2023-04-06fix(ws): export Server (#2575)Gravatar hiroki osame 1-13/+30
2023-04-06docs(CONTRIBUTING): referece development guide (#2576)Gravatar hiroki osame 1-1/+5
2023-04-05rebase (#1501)Gravatar dave caruso 2-144/+305
2023-04-05Update `typecheck` (#2572)Gravatar Colin McDonnell 3-4/+8
2023-04-05prependGravatar Jarred Sumner 1-7/+3
2023-04-05Add tests for `bun test` with preload scripts (#2566)Gravatar Jake Boone 2-1/+107
2023-04-05Disable buffering when we clear terminalGravatar Jarred Sumner 1-0/+2
2023-04-05PrettierGravatar Jarred Sumner 3-4/+4
2023-04-05fix(fetch.proxy) fix proxy authentication (#2554)Gravatar Ciro Spaciari 3-31/+186
2023-04-05fix: build warnings (#2562)Gravatar hiroki osame 4-4/+1
2023-04-05In Documentation, move --watch before the script name (#2569)Gravatar Lawlzer 1-4/+5
2023-04-05fix `deepEquals` with array holes and accessors (#2557)Gravatar Dylan Conway 2-10/+249
2023-04-05fix: modules to have null prototype (#2561)Gravatar hiroki osame 2-2/+9
2023-04-04:clock1: :clock2: :clock3:Gravatar Jarred Sumner 1-1/+1
2023-04-04Implement `import.meta.main` (#2556)Gravatar Jarred Sumner 10-8/+89
2023-04-04Dylan/fix some failing tests (#2544)Gravatar Jarred Sumner 10-29/+72
2023-04-04Add npm benchmark (#2555)Gravatar Colin McDonnell 13-1/+271
2023-04-03Use absolute paths morebun-v0.5.9Gravatar Jarred Sumner 2-6/+11
2023-04-03Fix test failureGravatar Jarred Sumner 1-15/+18