Reading Safari cookies from Perl

Did the Perl / Core Foundation bridging break in MacOS 10.11? This used to work:
use Foundation;
my $e = NSHTTPCookieStorage->sharedHTTPCookieStorage->cookies->objectEnumerator;
while (my $c = $e->nextObject and $$c) {
  print $c->domain->cString . ": " . $c->value->cString . "\n"; }
But now:
Can't locate object method "sharedHTTPCookieStorage" via package "NSHTTPCookieStorage" (perhaps you forgot to load "NSHTTPCookieStorage"?)

Previously.

Tags: , , , ,

11 Responses:

  1. ben says:

    It seems to be worse, they broke NSHTTPCookieStorage on 10.11 in Objective-C too!

    @import Foundation;
    int main() {
    NSLog(@"cookieStorage.count: %lu", [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies.count);
    }

    always prints: cookieStorage.count: 0

    On that note, Perl complains about not being able to locate NSHTTPCookieStorage because somebody "forgot" to put this in Foundation.pm:

    package NSHTTPCookieStorage;
    @ISA = qw(PerlObjCBridge);
    @EXPORT = qw( );

    If you put that in your Perl script before your usage of NSHTTPCookieStorage, the script will work. It just won't print anything, because the Foundation API doesn't work properly.

  2. ff says:

    This seems to work here


    use Foundation;

    package NSHTTPCookieStorage;
    @ISA = qw(PerlObjCBridge);
    @EXPORT = qw( );

    my $e = NSHTTPCookieStorage->sharedCookieStorageForGroupContainerIdentifier_("Cookies")->cookies->objectEnumerator;
    while (my $c = $e->nextObject) {
    if (!$$c) { exit(0); }
    print $c->domain->cString . ": " . $c->value->cString . "\n";
    }

  3. kwk says:

    Has Mac overall still been a good experience for you? I mean this genuinely and with no implication of anything else being better, because I know that everything is broken. I think I could become an embedded coffee machine programmer and still have to work around other people's stupid design decisions.

    • jwz says:

      Everything is broken, and MacOS has gotten decidedly flakier since 10.9 or so, but if you want a Unix machine with a GUI, there's really no other choice. Trying to use the Linux Self-Abuse Kit as a desktop is just... it's just madness. Why would you do that??

      I also use a few Mac Minis as headless servers, in places where I could probably get away with Linux or BSD, but why bother? For not-much-more money I know it will just work and not require me to re-learn which APIs and subsystems have been invented or fallen out of favor every six months. My time is worth more than that.

      • jwz says:

        And I realize we're talking about a broken MacOS API here, but this at least seems to just be a bug. If this was Linux, the API would have just completely changed, probably three times already, and I'd be expected to get at those cookies by using OAUTH2 to talk to NarniaLamppost which is the new service started by init that manages your cookies now, along with MIDI and your laptop's backlight. Oh, did I say OAUTH2? I meant OAUTH3.1 which doesn't actually exist yet but there's a draft on some guy's blog, I think you can find it on CADTplanet.net.

        • kwk says:

          I'm totally with you. I think my experience with linux was very similar to yours. My experience with basically every technology is that it's profoundly broken and I don't know what to do about this.

        • Paul Rain says:

          'init'? You've been lucky to have avoided recent developments in Lisux.

          • kwk says:

            I was also unaware. Wikipedia says "The design of systemd has ignited controversy within the free software community. Critics argue that systemd is overly complex and suffers continued feature creep, and that its architecture violates the design principles of Unix-like operating systems." [ https://en.wikipedia.org/wiki/Systemd ]

            This sounds exactly right.

      • I just wish they'd hire two guys to pick one of the package systems (ports, fink (deb), or brew), and make it work. I've given up, if I want a current (and I understand why the system isn't current, I'm not asking for that) Unix, I run a VM with Linux, be it on a window box or a Mac. If they did make a package system work, I'd buy their stuff to run at home, but, as it is, I use Windows at work (I could have had a mac, but I'd be the first in the department, and we do a lot of weird things, I don't want to have to be the one to figure out what works on a mac), and Linux at home (I'm cheap, it's what I do for a living, run a mac unless you know why you want a Linux box).

        Sigh, sadness.