App-FirefoxMultiAccountContainersUtils
view release on metacpan or search on metacpan
lib/App/FirefoxMultiAccountContainersUtils.pm view on Meta::CPAN
log_info "Writing $path ...";
File::Slurper::write_text($path, JSON::MaybeXS::encode_json($json));
[200];
}
$SPEC{firefox_mua_dump_identities_json} = {
v => 1.1,
summary => "Dump the content of identities.json",
description => <<'MARKDOWN',
MARKDOWN
args => {
%argspec0_profile,
},
};
sub firefox_mua_dump_identities_json {
require App::FirefoxUtils;
require Firefox::Util::Profile;
require JSON::MaybeXS;
my %args = @_;
my $res;
$res = _get_containers_json(\%args);
return $res unless $res->[0] == 200;
my $path = $res->[2]{path};
my $json = $res->[2]{content};
[200, "OK", $json];
}
$SPEC{open_firefox_container} = {
v => 1.1,
summary => "CLI to open URL in a new Firefox tab, in a specific multi-account container",
description => <<'MARKDOWN',
This utility opens a new firefox tab in a specific multi-account container. This
requires the Firefox Multi-Account Containers add-on, as well as another add-on
called "Open external links in a container",
<https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/>.
The way it works, because add-ons currently do not have hooks to the CLI, is via
a custom protocol handler. For example, if you want to open
<http://www.example.com/> in a container called `mycontainer`, you ask Firefox
to open this URL:
ext+container:name=mycontainer&url=http://www.example.com/
Ref: <https://github.com/mozilla/multi-account-containers/issues/365>
**Related topics**
In Google Chrome browser, profiles is what you would use to separate
sessions/cookies (and other things). Opening a URL in a specific profile from
the command-line is easier with Chrome:
% google-chrome --profile-directory="PROFILEDIRNAME" URL
where `PROFILEDIRNAME` is a directory name under the profiles directory,
typically `~/.config/google-chrome/` on Unix. You can use the
<prog:list-chrome-profiles> (with option `-l`) (from <pm:App::ChromeUtils>) to
list Chrome profiles.
MARKDOWN
args => {
%argspecopt_profile,
container => {
schema => 'str*',
completion => \&_complete_container,
req => 1,
pos => 0,
},
new_window => {
schema => 'bool*',
},
urls => {
'x.name.is_plural' => 1,
'x.name.singular' => 'url',
schema => ['array*', of=>'str*'],
pos => 1,
slurpy => 1,
},
extra_firefox_options_before => {
summary => 'Additional options (arguments) to put before the URLs',
schema => ['array*', of=>'str*'],
cmdline_aliases => {'b'=>{}},
},
extra_firefox_options_after => {
summary => 'Additional options (arguments) to put after the URLs',
schema => ['array*', of=>'str*'],
cmdline_aliases => {'a'=>{}},
},
},
features => {
},
examples => [
{
summary => 'Open two URLs in a container called "mycontainer"',
argv => [qw|mycontainer www.example.com www.example.com/url2|],
test => 0,
'x.doc.show_result' => 0,
},
{
summary => 'If URL is not specified, will open a blank tab',
argv => [qw|mycontainer|],
test => 0,
'x.doc.show_result' => 0,
},
{
summary => 'Open URL in a new tab in a new window',
argv => [qw|mycontainer www.example.com -b --new-window|],
test => 0,
'x.doc.show_result' => 0,
description => <<'MARKDOWN',
This command passes the `--new-window` option to `firefox`.
MARKDOWN
},
],
lib/App/FirefoxMultiAccountContainersUtils.pm view on Meta::CPAN
=head2 open_firefox_container
Usage:
open_firefox_container(%args) -> [$status_code, $reason, $payload, \%result_meta]
CLI to open URL in a new Firefox tab, in a specific multi-account container.
Examples:
=over
=item * Open two URLs in a container called "mycontainer":
open_firefox_container(
container => "mycontainer",
urls => ["www.example.com", "www.example.com/url2"]
);
=item * If URL is not specified, will open a blank tab:
open_firefox_container(container => "mycontainer");
=item * Open URL in a new tab in a new window:
open_firefox_container(
container => "mycontainer",
urls => ["www.example.com"],
extra_firefox_options_before => ["--new-window"]
);
This command passes the C<--new-window> option to C<firefox>.
=back
This utility opens a new firefox tab in a specific multi-account container. This
requires the Firefox Multi-Account Containers add-on, as well as another add-on
called "Open external links in a container",
L<https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/>.
The way it works, because add-ons currently do not have hooks to the CLI, is via
a custom protocol handler. For example, if you want to open
L<http://www.example.com/> in a container called C<mycontainer>, you ask Firefox
to open this URL:
ext+container:name=mycontainer&url=http://www.example.com/
Ref: L<https://github.com/mozilla/multi-account-containers/issues/365>
B<Related topics>
In Google Chrome browser, profiles is what you would use to separate
sessions/cookies (and other things). Opening a URL in a specific profile from
the command-line is easier with Chrome:
% google-chrome --profile-directory="PROFILEDIRNAME" URL
where C<PROFILEDIRNAME> is a directory name under the profiles directory,
typically C<~/.config/google-chrome/> on Unix. You can use the
L<list-chrome-profiles> (with option C<-l>) (from L<App::ChromeUtils>) to
list Chrome profiles.
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<container>* => I<str>
(No description)
=item * B<extra_firefox_options_after> => I<array[str]>
Additional options (arguments) to put after the URLs.
=item * B<extra_firefox_options_before> => I<array[str]>
Additional options (arguments) to put before the URLs.
=item * B<new_window> => I<bool>
(No description)
=item * B<profile> => I<firefox::local_profile_name::default_first>
(No description)
=item * B<urls> => I<array[str]>
(No description)
=back
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code
(200 means OK, 4xx caller error, 5xx function error). Second element
($reason) is a string containing error message, or something like "OK" if status is
200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth
element (%result_meta) is called result metadata and is optional, a hash
that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/App-FirefoxMultiAccountContainersUtils>.
=head1 SOURCE
Source repository is at L<https://github.com/perlancar/perl-App-FirefoxMultiAccountContainersUtils>.
=head1 SEE ALSO
"Open external links in a container" add-on,
L<https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/> (repo
at L<https://github.com/honsiorovskyi/open-url-in-container/>). The add-on also
( run in 2.143 seconds using v1.01-cache-2.11-cpan-64ef6c95b5d )