Skip to content

Instantly share code, notes, and snippets.

@durzo
Created December 16, 2019 18:58
Show Gist options
  • Save durzo/e5e7db5fe8f54f4eaf7ad69260400bb9 to your computer and use it in GitHub Desktop.
Save durzo/e5e7db5fe8f54f4eaf7ad69260400bb9 to your computer and use it in GitHub Desktop.
icingaweb2 pdfexport fix
diff --git a/library/Pdfexport/HeadlessChrome.php b/library/Pdfexport/HeadlessChrome.php
index 4342cc4..e034805 100644
--- a/library/Pdfexport/HeadlessChrome.php
+++ b/library/Pdfexport/HeadlessChrome.php
@@ -192,15 +192,17 @@ class HeadlessChrome
$path = $storage->resolvePath($path, true);
- $chrome = new Process(join(' ', [
+ $env = ['HOME'=>'/tmp'];
+ $chrome = new Process("exec ". join(' ', [
escapeshellarg($this->getBinary()),
static::renderArgumentList([
'--headless',
'--disable-gpu',
'--no-sandbox',
- '--remote-debugging-port=0'
+ '--remote-debugging-port=0',
+ '--user-data-dir=/tmp'
])
- ]));
+ ]),null,$env);
$loop = Factory::create();
$chrome->start($loop);
@@ -209,7 +211,6 @@ class HeadlessChrome
if (! preg_match(self::DEBUG_ADDR_PATTERN, trim($chunk), $matches)) {
return;
}
-
file_put_contents($path, $this->printToPDF($matches[1], $matches[2], isset($this->document)
? $this->document->getPrintParameters()
: []));
@@ -222,8 +223,10 @@ class HeadlessChrome
}
});
+ $loop->addTimer(2.0, function () use ($loop) {
+ $loop->stop();
+ });
$loop->run();
-
return $path;
}
@@ -272,13 +275,13 @@ class HeadlessChrome
} else {
throw new Exception('Expected base64 data. Got instead: ' . json_encode($result));
}
-
$page->close(); // We're done with the tab, tell this the browser
// close tab
$result = $this->communicate($browser, 'Target.closeTarget', [
'targetId' => $targetId
]);
+
if (! isset($result['success'])) {
throw new Exception('Expected close confirmation. Got instead: ' . json_encode($result));
}
diff --git a/vendor/textalk/websocket/lib/Base.php b/vendor/textalk/websocket/lib/Base.php
index 6b21975..3b37c67 100644
--- a/vendor/textalk/websocket/lib/Base.php
+++ b/vendor/textalk/websocket/lib/Base.php
@@ -170,7 +170,12 @@ class Base {
$this->send($status_str . $message, 'close', true);
$this->is_closing = true;
- $response = $this->receive(); // Receiving a close frame will close the socket now.
+ //$response = $this->receive(); // Receiving a close frame will close the socket now.
+
+ // And close the socket.
+ $response = true;
+ fclose($this->socket);
+ $this->is_connected = false;
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment