Skip to content

Commit

Permalink
Merge pull request #42 from tsmilan/EDAEASS-17236-fix-print-error
Browse files Browse the repository at this point in the history
Fix pdf printing failure
  • Loading branch information
tsmilan authored Oct 14, 2024
2 parents 9f788d5 + e94d639 commit 0fda704
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions classes/converter_chromium.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class converter_chromium extends converter {
'jsCondition' => '(string) A JavaScript condition to be evaluated, specified as a string.
It should return a boolean value indicating whether the condition has been met',
'jsConditionParams' => '(array) An array of parameters to pass to the Javascript function.',
'customFlags' => '(array) An array of flags to pass to the BrowserFactory class.'
];

/**
Expand All @@ -83,13 +84,17 @@ protected function generate_pdf_content(moodle_url $proxyurl, string $filename =
try {
$browseroptions = [
'headless' => true,
'noSandbox' => true
'noSandbox' => true,
];

if (isset($options['windowSize'])) {
$browseroptions['windowSize'] = $options['windowSize'];
}

if (isset($options['customFlags'])) {
$browseroptions['customFlags'] = $options['customFlags'];
}

$browserfactory = new BrowserFactory(helper::get_config($this->get_name() . 'path'));
$browser = $browserfactory->createBrowser($browseroptions);

Expand All @@ -107,7 +112,10 @@ protected function generate_pdf_content(moodle_url $proxyurl, string $filename =
$page->setUserAgent($options['userAgent']);
}

$page->navigate($proxyurl->out(false))->waitForNavigation();
// Wait until the page reaches a "network idle" state, which means that no more active
// network requests such as images or scripts are pending. A 60-second timeout is set to
// prevent it from hanging indefinitely if the network takes too long to become idle.
$page->navigate($proxyurl->out(false))->waitForNavigation(PAGE::NETWORK_IDLE, 60000);

$timeout = 1000 * helper::get_config($this->get_name() . 'responsetimeout');

Expand All @@ -116,7 +124,7 @@ protected function generate_pdf_content(moodle_url $proxyurl, string $filename =
$this->wait_for_js_condition($page, $jscondition, $jsconditionparams, $timeout);

$pdfoptions = array_filter($options, function($option) {
$renderoptions = ['windowSize', 'userAgent', 'jsCondition', 'jsconditionparams'];
$renderoptions = ['windowSize', 'userAgent', 'jsCondition', 'jsconditionparams', 'customFlags'];
return !in_array($option, $renderoptions);
}, ARRAY_FILTER_USE_KEY);

Expand Down

0 comments on commit 0fda704

Please sign in to comment.