Read cookies from URL

Hello,
is possible to read cookies from URL with HTMLViewer or with other components?

Cookies that are already stored in the user’s web browser or cookies that are being created from the web site you are looking at in the HTMLViewer?

yes

Both?

I want to grab cookies stored within my htmlviewer

Mac? Win? Linux?

Mac and Win

I want to grab cookie name, path, domain, expiration date and value

Add this event to the HTMLViewer :

Sub TitleChanged(newTitle as String) MsgBox newTitle End Sub

To get the cookies :

HTMLViewer1.ExecuteJavaScript("document.title=document.cookie;")

TitleChanged will fire any time the title is changed. For instance if you loadURL Google.com it will show Google initialy. Then when you executeJavaScript you will get all the cookies, separated by a semicolon (;).

Since the cookies list contain equal (=) you can suppose the title containing the cookies is one where Instr(newTitle, "=") > 0.

Hello Michel Bujardet,
with document.cookie I can’t get path, domain and expiration date

On Mac we have classes to get/set cookies in MBS Plugin:
http://www.monkeybreadsoftware.net/class-nshttpcookiestoragembs.shtml

For Windows with Internet Explorer (native renderer), we have the HTMLViewer.IECookieMBS property.

[quote=187999:@Daniele Murabito]Hello Michel Bujardet,
with document.cookie I can’t get path, domain and expiration date[/quote]

Your question was [quote]is possible to read cookies from URL with HTMLViewer or with other components?[/quote]It was not “I want to get cookies, path and expiration date”.

See MBS.

Could not the javascript in the ExecuteJavascript be modified to include path, domain and expiration?

The path, domain and expiration tell the browser whether or not to even return the cookie. I don’t think you’ll get them back when reading them.

There simply does not seem to exist any JavaScript method to get that information.

I don’t know what you are doing, or what you are trying to achieve, but you could always use a socket, set up the GET headers, and look at what comes back. Something like this:

HTTP/1.1 200 OK
Date: Mon, 18 May 2015 10:36:40 GMT
Server: Apache
Set-Cookie: PHPSESSID=1kuhqmq84rjrc105300lnhha62; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

( Hehe - that cookie looks a bit stale ).

[quote=188013:@Peter Job]I don’t know what you are doing, or what you are trying to achieve, but you could always use a socket, set up the GET headers, and look at what comes back. Something like this:

HTTP/1.1 200 OK
Date: Mon, 18 May 2015 10:36:40 GMT
Server: Apache
Set-Cookie: PHPSESSID=1kuhqmq84rjrc105300lnhha62; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

( Hehe - that cookie looks a bit stale ).[/quote]
This is what you get when a server sets a new cookie, but it’s no good for reading existing ones.

[quote=188013:@Peter Job]I don’t know what you are doing, or what you are trying to achieve, but you could always use a socket, set up the GET headers, and look at what comes back. Something like this:

HTTP/1.1 200 OK
Date: Mon, 18 May 2015 10:36:40 GMT
Server: Apache
Set-Cookie: PHPSESSID=1kuhqmq84rjrc105300lnhha62; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

( Hehe - that cookie looks a bit stale ).[/quote]

I want to grab every cookie that is released from the website. If I use the socket I can’t get client side cookies (for example google analytics).

OK sorry. If, say, on Win the HTMLViewer is based on MSIE, would the cookies not be where MSIE stores them? Likewise whatever you are calling to browse? I am sure there is code to unpack the obtuse file names used.

Or do I still misunderstand?