perl - Launch url in browser opening in non-default browser - perl

I try to launch my default browser and open to a specified URL as suggested here using something like:
use Browser::Open qw( open_browser );
my $url = 'http://www.google.com/';
open_browser($url);
But it opens it in Firefox even though Chromium is set to my default browser:
How do I get it to open in Chromium?

Perl has no concept of default browser. As you can see in its documentation, Browser::Open will go down the list of known browser invocation commands and use the first one that works. Firefox apparently happens to be higher on the list than Chromium.
If you want to invoke Chromium, then just invoke Chromium yourself. Something like this should do:
system("chromium \"$url\"")
(you might have to change the name of the executable, depending on your system and PATH)

Related

manifest.json display property has invalid option of browser

The documentation seems to state that there are four options for the "display" property within a manifest.json: fullscreen, standalone, minimal-ui and browser
I decided upon 'browser' for one of my apps, but the message from Chrome (Version 76) says "Manifest 'display' property must be one of 'standalone', 'fullscreen' or 'minimal-ui'". The message also appears if I leave 'display' undefined.
Is 'browser' an obsolete option or has it just not made it into the latest Chrome version yet?
(I probably should mention that the message appears in Chrome DevTools>application>manifest).
Valid options for display are fullscreen, standalone, minimal-ui and browser according to https://developer.mozilla.org/en-US/docs/Web/Manifest/display.
In order to show the Add to Home Screen Prompt, display must be set to must be one of: fullscreen, standalone, or minimal-ui, see https://developers.google.com/web/fundamentals/app-install-banners/
browser display option is like leaving the field empty.
When you use standalone it looks like native app. When you use fullscreen there is no status bar etc. Probably you want to use standalone, because fullscreen has very specific use-case (e.g. gaming).
I finally got around to reporting it as a bug.
https://bugs.chromium.org/p/chromium/issues/detail?id=1330323
The immediate response was...
The behaviour is seen from M-85.This is is a non regression issue
hence marking it as untriaged and requesting some one from dev team to
look into the issue.

Open browser in private=incognito mode from Thunderbird extension

I would like to open a URL in private mode from a Thunderbird extension. Right now, the following code works in "standard" non-private mode:
try {
var eps = Components.classes["#mozilla.org/uriloader/external-protocol-service;1"].
getService(Components.interfaces.nsIExternalProtocolService);
var ios = Components.classes["#mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
eps.loadURI(ios.newURI("http://www.example.com", null, null));
} catch (err) {}
Any idea how to achieve the same result in private mode? I'm interested to make it work with launching Chrome as the default browser. (Once again, Chrome is correctly launched with the code above).
You cannot really launch Firefox with a new url in a private window AFAIK. -private-window <url> will open a new private window, but still put the new tab in a regular one.
Chrome can be launched with chrome --incognito <url>, however you would need to launch it yourself via nsIProcess and therefore would first have to figure out where the chrome binary is.
If you can guarantee that the default handler is Chrome, then you might use nsIExternalProtocolService.getProtocolHandlerInfo(), use preferredApplicationHandler and QueryInterface that to nsILocalHandlerApp to find the .executable. Otherwise, you'll have to deal with the OS and/or known paths yourself.

Print page content

I just started playing with google chrome apps. I've searched the internet and haven't found the way to print the content of the windows. Tried using windows.print(), but nothing happened.
As far as I have read, the print() wont work since it is called in the background.html that does not have any content. How can I make the call at the correct place and send the content of the app to the printer?
Thank you in advance!
You're right that this can't be done through the Background page, since it is not rendered. What you'll need to do is inject a "content script" into the page you would like to print. The content script would contain the print command, and probably whatever would trigger the print command.
In a nutshell, "content scripts" are scripts that are injected into the pages a user browses. You can inject pretty much any JavaScript you like, and even inject entire JavaScript libraries like JQuery. More details can be found here:
https://developer.chrome.com/extensions/content_scripts.html
If you decide to use a popup window to trigger the print you can pass a message to the window you would like to print. Message passing is how the different components of an extension (background page, content script, popup) communicate. More info can be found here:
http://developer.chrome.com/extensions/messaging.html
Printing in apps is not yet supported, I believe. See
Issue 131279: async version of window.print()

Perl Dancer send_file Issue with Images

I have a Perl Dancer web application that uses GD to dynamically create images. I am trying to deliver these images to the user as PNG. For example:
package MyApp;
use Dancer ':syntax';
use GD;
...
get '/dynamic_image/:var1/:var2' => sub {
my $im = GD::Image->new(100,100);
my $black = $im->colorAllocate(0,0,0);
my $white = $im->colorAllocate(255,255,255);
$im->rectangle(10,10,90,90,$white);
my $png = $im->png;
return send_file( \$png, content_type => 'image/png', filename => params->{var1}."_".params->{var2}.".png" );
};
However, when accessing the above route, Chrome and Firefox don't seem to know what to do with the image data. If I try to use the route in Lightbox, Chrome complains. For example, when clicking on a link like this:
link
Chrome's console says:
Resource interpreted as Image but transferred with MIME type application/octet-stream: "http://www.example.com/dynamic_image/my/image".
It looks like Dancer is not using content_type correctly. Interestingly, IE8 seems to load the images just fine. Any idea what's going on? I'm currently running it standalone on Windows 7 with Strawberry Perl v5.16.2.
To explain the different behavior with IE: If IE encounters a Content-Type of application/octet-stream, it will attempt to scan the file to determine a more specific MIME type. That behavior is covered more here.
I recommend using the GET` commandline tool from Perl's LWP distribution to confirm what's going on. You can try this:
GET -sSe http://www.example.com/dynamic_image/my/image | less
The result should include among other things the Content-Type header. It sounds like you'll find that it says application/octet-stream. This starts to look like an issue with Dancer.
You didn't specify what version of Dancer you are using. Older versions did not support the content_type option to send_file(). If you are are reading the latest docs on CPAN and expecting them to apply to an older version, there could be some confusion.
It does not seem to be a dancer problem. There are other environments where it happens too.
Resource interpreted as Document but transferred with
MIME type image
After banging my head against this for awhile, I think I can answer my own question. Firefox actually tipped me off to a bug in my own code. Basically, when accessing the dynamically created image in Firefox, it would display a page with the HTTP request info along with the PNG data. I noticed that some debugging text was displayed on the page. It turns out that I left a print in one of the loops that generated the image data (I had used it to verify the image was being built correctly), and that text somehow made it into the "image" itself--which I assume caused Firefox and Chrome to freak out a bit. So this wasn't a Dancer or application bug, but a PEBKAC issue. Thanks for the input, everybody.

Can't see dynamically loaded code in Chrome Developer Tools 22

When I dynamically load a snippet of html containing javascript via AJAX, I cannot see that content in the source tab in the developer tools window in Chrome 22.0.1229.94. Tellingly, I went here
https://developers.google.com/chrome-developer-tools/docs/scripts-breakpoints#js_dynamic
This page shows an example developer tools window which is out of date. There is a button on the page to load a dynamic script and it does not show up in the source tab when you do.
As a work-around, I have found that adding
debugger;
to the script and reloading it will cause it to pause in the dynamically loaded code, but unfortunately, all the line numbers are greyed out and you can't set any breakpoints within the debugger.
Am I missing something here or what?
Thanks,
Rob
When you use a library or javascript code that you have loaded it dynamically, you can use the phrase
//# sourceURL=foo.js
at the beginning of your javascript code that foo.js is the name that will be assigned it. debugger will show it with that name.
This is true in chrome, and I think in firebug too.
In this case you can place a breakpoint in the dynamically loaded javascript code.
Possible duplicate of:
Is possible to debug dynamic loading JavaScript by some debugger like WebKit, FireBug or IE8 Developer Tool?
Don't know if this works or not in chrome (This definitely doesn't work for me now, may be in the past).
//# sourceURL=foo.js
Working Solution
For your dynamically loaded script via ajax to appear in your chrome source tool, you need to add the following line at the start or end (I prefer) location of your script file:
//# sourceURL=foo.js
And your script with name foo.js will appear at the left pane of source tab under (no domain) dropdown
->localhost
-- source/src
->(no domain)
-- foo.js
Alternatively you can add the below line in your script anywhere between the scripts.
debugger;
In chrome, you can use " debugger; " statement to break at a statement when debugger panel is open. Chrome will simply ignore this if the debugger panel is closed.
This will help stop your script in debugging mode and you will see your script in source (debugging) panel with name like VM****.
Hope this helps.
You can use //# sourceURL. Chrome doesn't seem to be supporting //# sourceURL for inline scripts. However, it does work on eval expressions. This article gives more details about naming eval blocks and naming of any anonymous functions in your code.
Instead of using eval, you can try embedding a script tag or JSONP may be.
Varunkumar Nagarajan
for me it happened on nodejs project.
i restarted server and open in new tab my app and tada!..
Alternatively, to fix this problem you can open developer tool in a seprate window by clicking the icon. Now reload your script, and it will shown in script tab as expected. I know this is not a solution but a work arround.