Skip to content

Instantly share code, notes, and snippets.

@gray
Created May 30, 2013 20:04
Show Gist options
  • Save gray/5680713 to your computer and use it in GitHub Desktop.
Save gray/5680713 to your computer and use it in GitHub Desktop.
Converts Firefox cookies into JSON so they can be imported into Chrome using the Edit Cookies extension.
#!/usr/bin/env perl
use 5.016;
use warnings;
use JSON;
use ORLite ();
my $file = shift or die 'Feed me firefox cookies sqlite file';
ORLite->import({ file => $file, package => 'DB' });
my ($true, $false) = (JSON::true, JSON::false);
my @cookies;
for my $cookie (DB::MozCookies->select) {
push @cookies, {
domain => $cookie->host,
expirationDate => $cookie->expiry,
hostOnly => $cookie->host eq $cookie->baseDomain ? $true : $false,
httpOnly => $cookie->isHttpOnly ? $true : $false,
name => $cookie->name,
path => $cookie->path,
secure => $cookie->isSecure ? $true : $false,
session => $false,
storeId => '0',
value => $cookie->value,
};
}
say JSON->new->utf8->pretty->encode(\@cookies);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment