spiritix / php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome
MIT License
112 stars 29 forks source link

Cookies are not sent to Server while fetching content of the URL #56

Closed drikpanchang closed 1 year ago

drikpanchang commented 1 year ago

I found some issues and want to check if there is any work around to fix them -

$pdfInputObj = new UrlInput();
$pdfHTMLURL = $this->getWebURLForPDFGeneration();
$pdfInputObj->setUrl($pdfHTMLURL);

$this->mPDFFileHandler = new FileOutput();
$this->mPDFBuilder = new Converter($pdfInputObj, $this->mPDFFileHandler);

$lang = ['name' => 'lang-key, 'value' => 'lang-value', 'domain' => '.app.localhost'];
$cookiesList = [];
$cookiesList[] = $lang;
$this->mPDFBuilder->setOption('cookies', $cookiesList);
$this->mPDFBuilder->convert();
LogFormat "%V:%p; %h; %{X-Forwarded-For}i; %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"  \"%{Cookie}i\""

The Apache2 log prints - localhost:80; 127.0.0.1; -; [12/Jun/2023:23:25:23 +0530] "GET /some-url.html HTTP/1.1" 200 83778 "-" "-" "-" Issue 1 - if User Agent is not set then our server deny the request but we can by-pass that check for localhost. However, User Agent was expected. Issue 2 - Cookies are not sent. It is show stopper for us.

Please check and let me know if these are real issues or we are not using the lib as expected.

drikpanchang commented 1 year ago

cookies are not set with localhost, is Chrome issue. https://bugs.chromium.org/p/chromium/issues/detail?id=56211 It seems there is no workaround to fix it. However, user agent issue can be fixed.