pofider / phantom-html-to-pdf

Highly scalable html to pdf conversion using phantom workers
MIT License
159 stars 33 forks source link

Include custom cookies in request #54

Closed chips5k closed 7 years ago

chips5k commented 7 years ago

Hi, not sure where else to post this, but i need the ability to include a cookie when phantom js requests a file. I can see how i might do this by modifying your source code (which i'd rather not do), but i cannot work out where/how and in what format to supply cookies in the initial conversion function.

Below is the code i am using, i'd assumed i could just pass a cookies property in the options object. Tried several different formats, and tried to trace through your code but had no luck.

conversion({ url: request.post.location', // waitForJS: true, // waitForJSVarName: 'ready_to_print' }, function(err, pdf) { console.log(pdf.logs); console.log(pdf.numberOfPages); pdf.stream.pipe(response); });

Tried:

cookie: [[name, value]] cookie: [{name: name, value: value}] cookie: ["name=value"]

None of the above worked.

I've looked at phantomjs itself which recommends using addCookie methods, but since i dont have access to the phantom objects themselves, im not sure how to go about this (again without modifying the code).

thanks!

Callem.

pofider commented 7 years ago

Hi,

you are right. This requires extending this package. Don't you want to try to implement this and send PR?

  1. Extend the conversion function options parameter with cookies object
  2. Iterate over the object properties in the phantomjs script and call addCookie
  3. The unit test could simply just add cookie, write it to console.log and assert the correct value is in the output.
  4. Update readme

The PR would be basically the same as this one - https://github.com/pofider/phantom-html-to-pdf/pull/46/files You would probably only use object instead of array to pass cookies.

What you think?

chips5k commented 7 years ago

Hi jan, ill give this a go and submit a pr if im succesful. Thanks for the pointers!

On Mon, 20 Mar 2017 at 9:35 pm, Jan Blaha notifications@github.com wrote:

Hi,

you are right. This requires extending this package. Don't you want to try to implement this and send PR?

  1. Extend the conversion function options parameter with cookies object
  2. Iterate over the object properties in the phantomjs script and call addCookie
  3. The unit test could simply just add cookie, write it to console.log and assert the correct value is in the output.
  4. Update readme

The PR would be basically the same as this one - https://github.com/pofider/phantom-html-to-pdf/pull/46/files You would probably only use object instead of array to pass cookies.

What you think?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pofider/phantom-html-to-pdf/issues/54#issuecomment-287723856, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZlydJuXhDwIfDgljj9CJJK-1HbYZOlks5rnlaOgaJpZM4MiANg .

chips5k commented 7 years ago

Hi Jan - unfortunately we didn't end up using phantomjs at my workplace - was consuming too much of my time for a really simple feature. So not sure when/if i'll get a chance to add this in. I'll try but just wanted to warn you.

Also FYI, i did give it a quick go this morning, but realized the code i had from the npm install was different from what is in your git repo - certain files were missing and their use had changed, e.g conversionScript instead of serverScript - confused me a bit.

On Tue, Mar 21, 2017 at 7:47 AM, callem pittard callem.pittard@gmail.com wrote:

Hi jan, ill give this a go and submit a pr if im succesful. Thanks for the pointers!

On Mon, 20 Mar 2017 at 9:35 pm, Jan Blaha notifications@github.com wrote:

Hi,

you are right. This requires extending this package. Don't you want to try to implement this and send PR?

  1. Extend the conversion function options parameter with cookies object
  2. Iterate over the object properties in the phantomjs script and call addCookie
  3. The unit test could simply just add cookie, write it to console.log and assert the correct value is in the output.
  4. Update readme

The PR would be basically the same as this one - https://github.com/pofider/phantom-html-to-pdf/pull/46/files You would probably only use object instead of array to pass cookies.

What you think?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pofider/phantom-html-to-pdf/issues/54#issuecomment-287723856, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZlydJuXhDwIfDgljj9CJJK-1HbYZOlks5rnlaOgaJpZM4MiANg .

pofider commented 7 years ago

Ok, sure....

The final scripts distributed to npm are created in npm prepublish or during npm tests. => The state of git master vs npm latest is currently the same except some minor changes done to readme which were not released yet.

chips5k commented 7 years ago

Hmm ok, i'm not super familiar with npm publishing - just did a quick check

On Tue, Mar 21, 2017 at 9:11 PM, Jan Blaha notifications@github.com wrote:

Ok, sure....

The final scripts distributed to npm are created in npm prepublish or during npm tests. => The state of git master vs and npm latest is currently the same except some minor changes done to readme which were not released yet.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pofider/phantom-html-to-pdf/issues/54#issuecomment-288032483, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZlyToXoAp2-71sir-ZsPBzsLsY_wmLks5rn6JKgaJpZM4MiANg .

chips5k commented 7 years ago

Yeah ok - just ignore me, realized prepareScripts.js is what writes those files =)

Busy week, brain not functioning so well....

On Tue, Mar 21, 2017 at 11:04 PM, callem pittard callem.pittard@gmail.com wrote:

Hmm ok, i'm not super familiar with npm publishing - just did a quick check - the files in npm that were not in master were serverScript.js, standaloneScript.js, but im going to hazard a guess that something is generating those files when you publish ?

On Tue, Mar 21, 2017 at 9:11 PM, Jan Blaha notifications@github.com wrote:

Ok, sure....

The final scripts distributed to npm are created in npm prepublish or during npm tests. => The state of git master vs and npm latest is currently the same except some minor changes done to readme which were not released yet.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pofider/phantom-html-to-pdf/issues/54#issuecomment-288032483, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZlyToXoAp2-71sir-ZsPBzsLsY_wmLks5rn6JKgaJpZM4MiANg .

pofider commented 7 years ago

Released in 0.5.0, big thanks to @chips5k for contribution