# Opening .url Files in Ubuntu

When browsing the web with Chrome for Android, I save the URLs on my Nextcloud server by sharing using the Nextcloud App. Each URL is then stored as a .url file looking like this

[InternetShortcut]
URL=https://devio.wordpress.com/

Today I noticed that those .url files cannot be opened on Ubuntu, i.e. a double-click won’t start a browser with the contained URL.

Instead, I get a an error dialog

Could not display “<HTML page title>.url”.

There is no application installed for “Internet shortcut” files.
Do you want to search for an application to open this file?

No     Yes

Clicking the Yes button, a toast message appears

which you have to click before it disappears, which finally opens the software installer:

Not good.

Surprisingly, Firefox does not register itself as an application to handle the .url file extension on Ubuntu. It also does not know that the Windows Firefox would know how to open the file.

More surprisingly, Ubuntu knows that .url files are “Internet shortcut” files, and have the associated MIME type application/x-mswinurl.

So I had to solve two problems:

• Retrieve the URL stored in a .url file
• Start Firefox using this URL using Ubuntu’s MIME type handling

### Retrieving the URL stored in a .url file

As shown above, a .url file is simply a text file in .ini format. In it’s simplest form, it contains a section [InternetShortcut] with a single Key “URL=”. The key’s value is the URL to navigate to.

With a little help from askubuntu, I figured out the command to extract the URL value

grep -Po 'URL=\K[^ ]+' *.url

Using the result of the grep operation as argument for firefox would look something like this:

firefox grep -Po 'URL=\K[^ ]+' "$1" After a bit of digging, I found how you can manually add MIME type handlers in Ubuntu. Following those instructions, I created a file /usr/share/applications/mswinurl.desktop (you need sudo in this directory) with the following content (spoiler: don’t copy this yet!): [Desktop Entry] Name=Firefox Shortcut GenericName=Firefox Shortcut Type=Application Exec=firefox grep -Po 'URL=\K[^ ]+' %U TryExec=firefox MimeType=application/x-mswinurl; Icon=firefox However, this did not work as intended, as I got an error message complaining about the backtick . So, if I cannot have shell operations in the .desktop file, let’s create a batch file /usr/local/bin/runurl and place the shell magic there: firefox grep -Po 'URL=\K[^ ]+' "$1" &

Don’t forget to make the batch file executable using

sudo chmod 755 runurl

and reference the runurl script rather than Firefox in /usr/share/applications/mswinurl.desktop:

[Desktop Entry]
Name=Firefox Shortcut
GenericName=Firefox Shortcut

Type=Application
Exec=runurl %U
TryExec=firefox
MimeType=application/x-mswinurl;
Icon=firefox

After creating the file, run

 sudo update-desktop-database

to register the new .desktop file.

Double-clicking a .url file now opens the URL in a new Firefox tab.

# Fixing “The media could not be played.”

Firefox would not play embedded videos on Twitter. At first it displays the video’s preview image, but as soon as the video is loaded, it replaces the preview image with a black box containing the simple message

The media could not be played.

Now my browser has the FlashBlock add-on installed, and it could be the culprit.

So I checked the network traffic, and found the following domains to be involved:

• abs.twimg.com for static content, such as gif, css, js
• pbs.twimg.com for profile thumbnails
• video.twimg.com for mp4’s

Adding video.twimg.com to FlashBlock’s whitelist did not change the behavior.

Whichever whitelisting semantics is built into FlashBlock, adding twitter.com solved my problem, and embedded videos now also play on Twitter.

# Software Inventory: Firefox Extensions

### Privacy

FoxyProxy Standard

Ghostery

Hide My IP

Block site

Flashblock

### Bookmark Management

Go Parent Folder

Show Parent Folder

### Development

Quick Locale Switcher

Most of the functionality of previous developer’s extensions Firebug and Web Developer seems to be included in standard Firefox.

### Screenshots

Screengrab (fix version)

Session Manager

# Detecting Screen Orientation Change

Browsers provide different means to detect screen orientation:

Documentation in the Mozilla Developer Network (linked above) states the first to be deprecated but currently still in the WhatWG Living Standard, whereas its documentation on the latter differs from the W3C documentation.

According to documentation, detection of screen orientation change can be achieved by implementing handlers for the events

• window.orientationchange
• screen.orientation.change
• window.matchMedia() listener
• window.resize

but specific browsers may not support all of these events, with window.resize being the catch-all solution if everything else fails.

So based on SO answers and this blog and this blog I came up with a solution that currently seems to work, and a couple of findings:

• window.orientation gives the angle on mobile browsers only – desktop browsers always contain 0 (zero).
• Similarly, window.onorientationchange is only supported by mobile browsers.
• screen.orientation (and its browser-spezific siblings mozOrientation and msOrientation) contains the angle in its angle property. IE11 does support support screen.orientation on Win7. Mobile Chrome (35) and the Android 4.4.2 Browser do not seem to support it either.
• Of the browsers I tested, none seem to implement the event screen.orientation.onchange.
• Orientation change can be detected using the window.matchMedia() listener on both mobile and desktop browsers which support mediaqueries and its orientation selector.
• In desktop browsers, orientation can only be derived from $(window).width() and$(window).height(), or from the .matches property of a matchMedia listener.

Note that all this need not apply for older browsers, not even the values of window.orientation! (See SO, SO, SO, Giff’s note)

So here now is my JavaScript code for screen orientation change detection:

function doOnOrientationChange(src)
{
if (window.console && console.log)
console.log("width " + $(window).width() + " height " +$(window).height());

var orientation = {
angle: window.orientation,
type: ("onorientationchange" in window) ? "mobile" : "desktop"
};

if (window.screen) {
var o = window.screen.orientation || window.screen.mozOrientation
|| window.screen.msOrientation || orientation;
orientation = { angle: o.angle, type: o.type };
} else if ((window.orientation === 0) || window.orientation) {
orientation = { angle: window.orientation, type: "" + window.orientation + " degrees" };
}

if (!("onorientationchange" in window)) {
var w = $(window).width(), h =$(window).height();
var a = (w > h) ? 90 : 0;
orientation.angle = a;
if (window.console && console.log)
console.log("angle := " + a + " " + orientation.angle);
}

var jsonOrientation = JSON.stringify(
{ angle: orientation.angle, type: orientation.type });

switch(orientation.angle)
{
case -90:
case 90:
// we are in landscape mode
$().toastmessage('showNoticeToast', src + ' landscape ' + " " + jsonOrientation); if (window.console && window.console.log) console.log(src + ' landscape ' + " " + jsonOrientation);$("#orientation").text(src + ' landscape ' + " " + jsonOrientation);
break;
case 0:
case 180:
// we are in portrait mode
$().toastmessage('showNoticeToast', src + ' portrait ' + " " + jsonOrientation); if (window.console && window.console.log) console.log(src + ' portrait ' + " " + jsonOrientation);$("#orientation").text(src + ' portrait ' + " " + jsonOrientation);
break;
default:
// we have no idea
$().toastmessage('showNoticeToast', src + ' unknown ' + " " + jsonOrientation); if (window.console && window.console.log) console.log(src + ' unknown ' + " " + jsonOrientation);$("#orientation").text(src + ' unknown ' + " " + jsonOrientation);
break;
}
}

$(function () { if ("onorientationchange" in window) window.addEventListener('orientationchange', function() { doOnOrientationChange("window.orientationchange"); }); //window.addEventListener('resize', // function() { doOnOrientationChange("window.resize") }); if (window.screen && window.screen.orientation && window.screen.orientation.addEventListener) window.screen.orientation.addEventListener('change', function() { doOnOrientationChange("screen.orientation.change"); }); if (window.matchMedia) { var mql = window.matchMedia("(orientation: portrait)"); mql.addListener(function(m) { if (m.matches) { doOnOrientationChange("mql-portrait"); } else { doOnOrientationChange("mql-landscape"); } }); } doOnOrientationChange("init"); }); (I put the window.resize handler into comments because it generates too may events on desktop browsers.) In this sample code, detection change only causes output of angle and orientation type to •$().toastmessage() – a jQuery extension
• console.log
• \$(“#orientation”).text() – a jQuery call

Of course, your handlers may perform some useful actions…

# Browser Screenshot Extensions

If you want to take a screenshot of your current browser window, there’s always good old ALT-Printscreen, but this function captures the whole window, not just the contents, and copies it to the clipboard. Then you still need to open a graphics editor, such as Paint.Net, to crop, edit, and save the image.

There are, however, a couple of browser extensions to simplify the process, and support capturing the complete page contents, rather than just the visible part of the page.

Here’s the list of extensions I use:

### Firefox

In Firefox, I use Screengrab (fix version). It allows you to save or copy-to-clipboard the complete page, the visible part, or a selected area of the current page.

In the settings, you can define the pattern of the file name of the saved image (default: HTML Title and timestamp), and the text that is generated at the top of the image (default: URL). The option “Quickly save” won’t prompt you for a file name.

I love this extension for Firefox – however, if the screenshot gets too big (about 1.5Mb on Win32, 3Mb on Win32), it silently fails and generates .png files of size 0).

### Chrome

The extension Screen Capture (by Google) is now unsupported, and it did not work (read: the menu buttons did not invoke any recognizable action) on the latest versions of Chrome.

The extension Awesome Screenshot: Capture & Annotate supports capturing the complete page, the visible and a selected part of the page. After capturing, a simply picture editor allows you to crop the picture, or add simple graphics and text to the image. The file name of the saved image defaults to the page’s Title, but can be edited in the Save As dialog.

Unfortunately, only the command “Capture visible part of page” works on Facebook pages – both “entire page” and “selected area” fail to capture.

Finally, the extension Full Page Screen Capture simply generates an image of the complete page, and displays it in a new tab. From there, you need to invoke Save (ctrl-S) to save the image to the default directory. File name pattern is “screencapture-” plus the current URL. This extension provides no options.

# Feature Request

You know that your product is missing a critical feature, if a quick search (case in point: “Firefox search bookmark folder name”) brings up forum entries dating back at least 5 years:

“firefox search bookmark folder name”

# Firefox Flash Focus Finally Fixed?

This issue has been bothering me for at least half a year, and others too: If you open a page in Firefox that contains Flash content, the current Firefox window will lose the focus to some other window depending on your mood, the moon phase, and the current value of Guid.NewGuid().

After updating to Firefox 18 and Flash 11.5.502.146, this behavior does not show anymore.

Did they really fix? *sigh*

Update 13-01-13

It seems not. I’ll try the fix posted on Mozilla support #929688:

ProtectedMode=0

# Latest Firefox issues

I honestly get more and more reluctant to update each and every piece of software, simply because UPDATES BREAK EVERYTHING.

Most recently example: Firefox.

As a happy user of Firefox since Netscape I occasionally dare to update the software (I mentioned reluctance? I stayed on 3.6.x until an upgrade to 8 or so was unavoidable). The last version that ran smoothly for me was 13.0.

Then came 13.0.1, and problems started: When you opened a link in a new tab, Firefox lost focus after a couple of seconds. From the bug reports I read it seemed to be a problem with the Flash plugins. No rescue in sight.

I noticed that the scrolling was swifter, though. Subjective impression.

I hoped 14.0.1 would solve that focus problem, just to find out that initial scrolling on a page only started after a delay, sometimes a couple of seconds, with CPU usage hogging one core. Plus, the focus problem remained.

I also noticed that the font in the address bar and search bar was a bit smaller, and looked slightly distorted and blurred.

Not amused.

So, back to Firefox 13.0.

# Automatically updating Custom DotNetNuke Modules using Selenium IDE for Firefox

If you develop DNN modules and need to support several installations in sync, any automated help is welcome.

I tried to use Selenium to automate Firefox to upload module packages into a DNN installation. (I did not find any references as to whether DNN has a built-in update mechanism for custom modules). Download Selenium IDE and press Record.

The result is a Selenium Test Case that performs the following operations

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>dnn2ml update BGT.Flash</title>
<body>
<tr><td rowspan="1" colspan="3">dnn2ml update BGT.Flash</td></tr>
<tr>
<td>open</td>
<td></td>
</tr>

Retrieve the login URL by right-clicking the Login button and copying the URL. The tabid usually changes between installations.

<tr>
<td>type</td>
<td>host</td>
</tr>
<tr>
<td>type</td>
</tr>

<tr>
<td>clickAndWait</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td></td>
</tr>

I  added these two steps to change to Edit mode (I have no idea how the View/Edit mode is set right after login). This will cause a timeout if DNN is already in Edit mode.

<tr>
<td>select</td>
<td>id=dnn_cp_RibbonBar_ddlMode</td>
<td>label=Edit</td>
</tr>
<tr>
<td>clickAndWait</td>
<td>css=option[value="EDIT"]</td>
<td></td>
</tr>

Invoke Install Extension Wizard

<tr>
<td>click</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=dnn_ctr_Install_wizInstall_cmdBrowse</td>
<td>C:\path\to\MyModule\packages\MyModule_00.00.01_Source.zip</td>
</tr>

Select package file to be uploaded

<tr>
<td>clickAndWait</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>id=dnn_ctr_Install_wizInstall_chkRepairInstall</td>
<td></td>
</tr>

This is for updating modules, so we need to check the Repair flag

<tr>
<td>clickAndWait</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>//body[@id='Body']/div[4]/div/a[2]</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody></table>
</body>
</html>`