Issue with WebGadget in Maverick related to cookies

Mac OSX specific forum
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Issue with WebGadget in Maverick related to cookies

Post by bbanelli »

Greetings,

first of all, Merry Christmas!

This is not entirely related strictly to PureBasic, but has its repercussions, so here it is - there's a small issue regarding settings of WebGadget in Maverick. Cookies are blocked by default in Safari and they need to be enabled manually, FWIW.

http://i44.tinypic.com/ri9ij6.pngt

Now, is there an option to set that option via simple oneliner/command line/PureBasic command?

With my best,

Bruno
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Issue with WebGadget in Maverick related to cookies

Post by bbanelli »

Probably not the most elegant way, but...

http://youtu.be/FyyX6SHEydI?hd=1

http://dev.banelli.biz/ChangeSafariCookies.scpt

Code: Select all

tell application "System Events"
	tell application "Safari" to activate
	tell process "Safari"
		keystroke "," using command down
		delay 3
		tell window 1
			click button "Privacy" of tool bar 1
			delay 3
			click radio button "From third parties and advertisers" of radio group 1 of group 1 of group 1
		end tell
	end tell
	tell application "Safari" to quit
end tell
Hope it helps,

Bruno
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Issue with WebGadget in Maverick related to cookies

Post by Shardik »

bbanelli wrote:Probably not the most elegant way, but...

http://youtu.be/FyyX6SHEydI?hd=1

http://dev.banelli.biz/ChangeSafariCookies.scpt
Bruno,

thank you for your effort of demonstrating how to change the cookie policy in Safari with your YouTube video using Apple script! I think that using a script to change the cookie policy is the only way for OS X Lion and newer. In Snow Leopard it is still possible to change the cookie policy with a simple PureBasic command! After executing the code example below and changing the setting on Snow Leopard, you have to close Safari (with Cmd+Q) and restart Safari. Then you will observe that the setting has changed. In Lion and Mountain Lion (and presumably Mavericks) this doesn't work anymore! I assume that newer Safari versions save the cookie policy when closing and restore the saved setting on a restart for safety reasons...

Nevertheless in your own programs using the WebGadget it should be possible to change the cookie policy with my example code.

Code: Select all

CookieStorage = CocoaMessage(0, 0, "NSHTTPCookieStorage sharedHTTPCookieStorage")

If CookieStorage
  OpenWindow(0, 270, 100, 260, 117, "Change cookie settings")
  FrameGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Block cookies:")
  OptionGadget(1, 20, 80, WindowWidth(0) - 20, 20, "Never")
  OptionGadget(2, 20, 55, WindowWidth(0) - 20, 20, "Always")
  OptionGadget(3, 20, 30, GadgetWidth(0) - 20, 20, "From third parties and advertisers")

  CookiePolicy = CocoaMessage(0, CookieStorage, "cookieAcceptPolicy")
  SetGadgetState(CookiePolicy + 1, #True)

  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
        Break
      Case #PB_Event_Gadget
        SelectedGadget = EventGadget()

        If SelectedGadget >= 1 And SelectedGadget <= 3
          CookiePolicy = SelectedGadget - 1
          CocoaMessage(0, CookieStorage, "setCookieAcceptPolicy:", CookiePolicy)
        EndIf
    EndSelect
  ForEver
EndIf
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Issue with WebGadget in Maverick related to cookies

Post by bbanelli »

@Shardik, thank you very much for your code, I'll make sure to test it and report back to forum!
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Post Reply