-
Notifications
You must be signed in to change notification settings - Fork 13
Implement Webdriver #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheSyscall
wants to merge
60
commits into
main
Choose a base branch
from
webdriver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
c803fcd
Removed dependency on ReactPHP
TheSyscall b04bf63
Install php-webdriver
TheSyscall 529a1c7
Add types to printable html document
TheSyscall ec4097f
Use str_starts_with whereever possible
TheSyscall a890086
Add method to create parameters for printing with the webdriver
TheSyscall 1607807
Add webdrivers for chrome and gecko (firefox)
TheSyscall 42fb217
Use destructor instead of close method
TheSyscall 380b66a
Rewrite Pdfexport hook
TheSyscall 7a28a6a
Convert the HeadlessChrome class into a PdfPrintDriver
TheSyscall a634193
Move and rename HeadlessChrome to HeadlessChromeDriver
TheSyscall 1e255ef
Rename $targetId -> $frameId
TheSyscall 835e92b
Always waitForPageLoad after setting content
TheSyscall 059642c
Implement basic driver selection
TheSyscall 1168851
Fix form connection validation
TheSyscall c66980d
Use chrome Page.printToPDF
TheSyscall 48d7829
Fix coverpage creation
TheSyscall 4161126
FIXUP: remove comment
TheSyscall b863a7a
Use try catch
TheSyscall fb9f483
Format changes
TheSyscall df37ddb
Rename Driver to Backend
TheSyscall 3457afc
Allow for filesystem based html transfer for HeadlesChromeBackend
TheSyscall 3becc7f
Change ConfigController to CompatController
TheSyscall ea4ce28
Move BackendConfigForm away from ZendForms
TheSyscall 751d564
Change element order to reflect precedence
TheSyscall f2fc458
Add headers and short descriptions
TheSyscall 408175c
Require two underscores to divide section and key
TheSyscall fbdc9dc
Move initialization of the backend to the backend locator
TheSyscall 299000b
Add license headers
TheSyscall 0680aa4
Use outerHTML instead of innerHTML to preseve class names on the body…
TheSyscall 5e61ca1
Remove unused methods
TheSyscall cafe3a7
Explicitly call close on the backend
TheSyscall bf2c076
Fixup: clear header & set transfer mode
TheSyscall f4d2fc3
Manually close filestorage
TheSyscall eb13c9b
Wait for chrome to close and force close it after a timeout
TheSyscall 059f197
Use constants instead of magic numbers
TheSyscall 93766d0
Relicense to GPL-3.0-only and add SPDX license headers
TheSyscall 7df8e4b
Code style changes
TheSyscall 0d7a86b
fixup! Code style changes
TheSyscall 1b1e3e7
Use Callout instead of building something custom
TheSyscall ef93d16
Implement WebDriver Protocol with GuzzlePHP
TheSyscall e48d408
Use new WebDriver implementation
TheSyscall 77ae387
Add support for layout plugins to ChromeWebdriver
TheSyscall 40e04e1
Code style changes
TheSyscall 55a5a44
Revert "Install php-webdriver"
TheSyscall aa7704c
Add missing license headers and remove unused files
TheSyscall c5ab073
Code review suggestions
TheSyscall 92a0d2b
Use ConfigForm in IW2
TheSyscall 085922b
Use 0/1 instead of n/y
TheSyscall eef4330
Move script blocks into separate JavaScript files
TheSyscall 5854c67
Update config form to allow for an arbitrary number of backends
TheSyscall 1dc3217
Document webdriver installation
TheSyscall 322bbeb
Add docstrings
TheSyscall b08e5e2
Use ShellCommand abstraction
TheSyscall 174faf2
Add a function to check if adding a cover page is supported
TheSyscall 958467f
Fix a deprecation with unset member access
TheSyscall 0a5dfa2
fixme! Docstrings for ShellCommand
TheSyscall 907a1fd
Bring back htmlToPdf function
TheSyscall 6861696
Store the last working backend instance
TheSyscall 50f297c
Remove types to stay backward compatible
TheSyscall 0cec004
Change `first` method to mimic the behaviour of the base class
TheSyscall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| <?php | ||
|
|
||
| // SPDX-FileCopyrightText: 2019 Icinga GmbH <https://icinga.com> | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| namespace Icinga\Module\Pdfexport\Forms; | ||
|
|
||
| use Exception; | ||
| use Icinga\Module\Pdfexport\Backend\Chromedriver; | ||
| use Icinga\Module\Pdfexport\Backend\Geckodriver; | ||
| use Icinga\Module\Pdfexport\Backend\HeadlessChromeBackend; | ||
| use Icinga\Web\Form\ConfigForm; | ||
| use ipl\Validator\CallbackValidator; | ||
|
|
||
| class BackendConfigForm extends ConfigForm | ||
| { | ||
| public function assemble(): void | ||
| { | ||
| $this->addSectionNameElement(); | ||
|
|
||
| $this->addElement('number', 'priority', [ | ||
| 'label' => $this->translate('Priority'), | ||
| 'required' => true, | ||
| 'placeholder' => 100, | ||
| 'min' => 0, | ||
| 'description' => $this->translate('The priority of the backend. A lower priority will be used first.'), | ||
| ]); | ||
|
|
||
| $this->addElement('select', 'type', [ | ||
| 'label' => $this->translate('Type'), | ||
| 'multiOptions' => [ | ||
| '' => sprintf(' - %s - ', t('Please choose')), | ||
| 'chrome_webdriver' => t('Chrome WebDriver'), | ||
| 'firefox_webdriver' => t('Firefox WebDriver'), | ||
| 'remote_chrome' => t('Headless Chrome (Remote)'), | ||
| 'local_chrome' => t('Headless Chrome (Local)'), | ||
| ], | ||
| 'required' => true, | ||
| 'class' => 'autosubmit', | ||
| ]); | ||
|
|
||
| $type = $this->getPopulatedValue('type') ?? $this->getConfigValue('type'); | ||
|
|
||
| switch ($type) { | ||
| case 'remote_chrome': | ||
| $this->addElement('text', 'host', [ | ||
| 'label' => $this->translate('Host'), | ||
| 'description' => $this->translate('Host address of the server with the running web browser.'), | ||
| 'required' => true, | ||
| 'validators' => [ | ||
| new CallbackValidator(function ($value, CallbackValidator $validator) { | ||
| $port = $this->getValue('port') ?: 9222; | ||
|
|
||
| try { | ||
| $chrome = HeadlessChromeBackend::createRemote($value, $port); | ||
| $version = $chrome->getVersion(); | ||
| } catch (Exception $e) { | ||
| $validator->addMessage($e->getMessage()); | ||
| return false; | ||
| } | ||
|
|
||
| if ($version < HeadlessChromeBackend::MIN_SUPPORTED_CHROME_VERSION) { | ||
| $validator->addMessage(t( | ||
| 'Chrome/Chromium supporting headless mode required' | ||
| . ' which is provided since version %s. Version detected: %s', | ||
| )); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| }), | ||
| ], | ||
| ]); | ||
|
|
||
| $this->addElement('number', 'port', [ | ||
| 'label' => $this->translate('Port'), | ||
| 'description' => $this->translate('Port of the chrome developer tools. (Default: 9222)'), | ||
| 'placeholder' => 9222, | ||
| 'min' => 1, | ||
| 'max' => 65535, | ||
| ]); | ||
|
|
||
| break; | ||
|
|
||
| case 'local_chrome': | ||
| $this->addElement('text', 'binary', [ | ||
| 'label' => $this->translate('Binary'), | ||
| 'placeholder' => '/usr/bin/google-chrome', | ||
| 'description' => $this->translate('Path to the binary of the web browser.'), | ||
| 'validators' => [ | ||
| new CallbackValidator(function ($value, CallbackValidator $validator) { | ||
| if (empty($value)) { | ||
| return true; | ||
| } | ||
|
|
||
| try { | ||
| $chrome = (HeadlessChromeBackend::createLocal($value)); | ||
| $version = $chrome->getVersion(); | ||
| } catch (Exception $e) { | ||
| $validator->addMessage($e->getMessage()); | ||
| return false; | ||
| } | ||
|
|
||
| if ($version < HeadlessChromeBackend::MIN_SUPPORTED_CHROME_VERSION) { | ||
| $validator->addMessage(t( | ||
| 'Chrome/Chromium supporting headless mode required' | ||
| . ' which is provided since version %s. Version detected: %s', | ||
| )); | ||
| } | ||
|
|
||
| return true; | ||
| }), | ||
| ], | ||
| ]); | ||
|
|
||
| $this->addElement('checkbox', 'force_temp_storage', [ | ||
| 'label' => $this->translate('Use temp storage'), | ||
| 'description' => $this->translate( | ||
| 'Use temp storage to transfer the html to the local chrome instance.' | ||
| ), | ||
| 'checkedValue' => '1', | ||
| 'uncheckedValue' => '0', | ||
| ]); | ||
|
|
||
| break; | ||
|
|
||
| case 'firefox_webdriver': | ||
| case 'chrome_webdriver': | ||
| $this->addElement('text', 'host', [ | ||
| 'label' => $this->translate('Host'), | ||
| 'description' => $this->translate('Host address of the webdriver server'), | ||
| 'required' => true, | ||
| 'validators' => [ | ||
| new CallbackValidator(function ($value, CallbackValidator $validator) use ($type) { | ||
| $port = $this->getValue('port') ?: 4444; | ||
|
|
||
| try { | ||
| $url = "$value:$port"; | ||
| $backend = match ($type) { | ||
| 'chrome_webdriver' => new Chromedriver($url), | ||
| 'firefox_webdriver' => new Geckodriver($url), | ||
| default => throw new Exception("Invalid webdriver type $type"), | ||
| }; | ||
|
|
||
| if (! $backend->isSupported()) { | ||
| $validator->addMessage( | ||
| t('The webdriver server reports that it is unable to generate PDFs'), | ||
| ); | ||
| return false; | ||
| } | ||
| } catch (Exception $e) { | ||
| $validator->addMessage($e->getMessage()); | ||
| return false; | ||
| } | ||
| return true; | ||
| }), | ||
| ], | ||
| ]); | ||
|
|
||
| $this->addElement('number', 'port', [ | ||
| 'label' => $this->translate('Port'), | ||
| 'description' => $this->translate('Port of the webdriver instance. (Default: 4444)'), | ||
| 'placeholder' => 4444, | ||
| 'min' => 1, | ||
| 'max' => 65535, | ||
| ]); | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| $this->addButtonElements(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.