qutebrowser / qutebrowser

A keyboard-driven, vim-like browser based on Python and Qt.
https://www.qutebrowser.org/
GNU General Public License v3.0
9.67k stars 1.01k forks source link

Set as default browser #22

Open The-Compiler opened 10 years ago

The-Compiler commented 10 years ago

There should be an easy cross-platform way to set qutebrowser as the default system browser.

Implementation:

User interface:

A new command would be over the top, and adding a setting is confusing as well. Probably just a commandline argument, and maybe a hidden command.

The-Compiler commented 10 years ago

How dwb does it:

static gboolean
application_set_default(const char *text)
{
    gboolean ret = false;
    GDesktopAppInfo *info = g_desktop_app_info_new("dwb.desktop");
    char **token = NULL;
    if (info == NULL)
    {
        dwb_set_error_message(dwb.state.fview, "No desktop file found");
        return ret;
    }
    if (text == NULL || *text == '\0')
    {
        g_app_info_set_as_default_for_type(G_APP_INFO(info), "text/html", NULL);
        g_app_info_set_as_default_for_type(G_APP_INFO(info), "text/xml", NULL);
        g_app_info_set_as_default_for_type(G_APP_INFO(info), "application/xhtml+xml", NULL);
        g_app_info_set_as_default_for_type(G_APP_INFO(info), "x-scheme-handler/http", NULL);
        g_app_info_set_as_default_for_type(G_APP_INFO(info), "x-scheme-handler/https", NULL);
        ret = true;
    }
    else
    {
        token = g_strsplit(text, " ", -1);
        if (token[0] != NULL && token[1] != NULL)
        {
            if (!g_strcmp0(token[0], "mimetype"))
            {
                for (int i=1; token[i]; i++)
                    g_app_info_set_as_default_for_type(G_APP_INFO(info), token[i], NULL);
                ret = true;
            }
            else if (!g_strcmp0(token[0], "extension"))
            {
                for (int i=1; token[i]; i++)
                    g_app_info_set_as_default_for_extension(G_APP_INFO(info), token[i], NULL);
                ret = true;
            }
        }
        g_strfreev(token);
    }
    g_object_unref(info);
    return ret;
}
The-Compiler commented 9 years ago

This probably won't make it into v0.1.

The-Compiler commented 9 years ago

Retargeting this to v0.3 because I want to get v0.2 out ASAP.

arp242 commented 9 years ago

There's PyXDG from the freedesktop people.

The-Compiler commented 9 years ago

I only see installing MIME data which could be relevant, but the only thing that does is copying a file...

mrjovanovic commented 8 years ago

Just a note, for OS X, this little script does exactly what you want: https://github.com/kerma/defaultbrowser

The-Compiler commented 8 years ago

For OS X, when building the custom .dmg (#384), probably this should work.

edi9999 commented 8 years ago

Any updates on this ? Is they any easy way to set qutebrowser as your default browser when you open urls from anywhere ?

The-Compiler commented 8 years ago

For OS X? I need to check how I could get that stuff into my packages plist, but that's not a high-priority thing at the moment. Have you tried the thing @mrjovanovic linked?

edi9999 commented 8 years ago

No I'm on fedora/i3wm, but I don't know how to configure that stuff

mrjovanovic commented 8 years ago

Because of the tight integration of Gnome and Fedora, I think you'd have to do that in the Gnome System Settings/gconf-editor. More info on the appropriate keys here:

https://lists.fedoraproject.org/pipermail/users/2013-July/438306.html

On Fri, Jun 03, 2016 at 08:54:46AM -0700, Edgar Hipp wrote:

No I'm on fedora/i3wm, but I don't know how to configure that stuff


You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/The-Compiler/qutebrowser/issues/22#issuecomment-223617964

-Milos

edi9999 commented 8 years ago

I ended up doing xdg-settings set-default-browser qutebrowser

RomanSC commented 8 years ago

I believe xdg-settings and xdg-mime just edit a config called:

~/.local/share/applications/mimeapps.list

I followed https://wiki.archlinux.org/index.php/Default_applications#Set_the_default_browser without any success, it was editing the above mentioned config.

I found ~/.config/mimeapps.list which also contains some application defaults and was only able to change qutebrowser to my default by editing this file.

Using Arch Linux and i3wm

lahwaacz commented 8 years ago

@RomanSC You're right, that's most likely one of many bugs of xdg-utils. The ~/.local/share/applications/mimeapps.list file is deprecated and ignored for reading if ~/.config/mimeapps.list exists (see the standard).

xtuc commented 8 years ago

@The-Compiler: sorry for the duplicate.

I have the same issue.

qutebrowser v0.7.0
Platform: Darwin-14.5.0-x86_64-i386-64bit, 64bit
OS Version: 10.10.5, x86_64
m2habert commented 8 years ago

@mrjovanovic

Just a note, for OS X, this little script does exactly what you want: https://github.com/kerma/defaultbrowser

Not working here (Mac OS 10.11.2): QB simply does not show as a "handler" of urls to the OS X

(defaultbrowser Error message : qutebrowser is not available as a HTTP browser )

¿Did you use it succesfully?

The-Compiler commented 8 years ago

I'd guess you need to use the full path to the qutebrowser executable inside qutebrowser.app maybe?

m2habert commented 8 years ago

I don't think it makes any difference: defaultbrowser lists the same list of "available" browsers presented at the OS control panel...

I tried it out anyway, here is the output:


/Applications/qutebrowser.app/Contents/MacOS/qutebrowser is not available as a HTTP browser
Available browsers:
- iterm2
- safari
- realplayer
- mpv
- vlc
- waterfox
- gcal
- firefox
- slimtimer
m2habert commented 8 years ago

@The-Compiler previouly replyed:

There's probably no qutebrowser code at all involved, but you'd need to modify the PyInstaller config to use an Info.plist which registers qutebrowser as a web browser I think.

I modified QB's plist following http://apple.stackexchange.com/questions/219582/default-browser-plist-location/219584#219584 and, after copying the new version of the qutebrowser.app package, the OS recognizes QB as a "possible browser" (and defaulbrowser works).

But QB still doesn't handle opened files (like .jpg s) or piped urls (I use Karabiner to open several pages) or even "drag-n-drop-over-the-icon".

I then tried copying a Firefox plist and editing any string in it related to FFx or Mozilla to the equivalent in QB's original plist: still got the same result; I can set QB as my default browser, but it doesn't work as such.

¿Any ideas?

The-Compiler commented 8 years ago

I modified QB's plist following http://apple.stackexchange.com/questions/219582/default-browser-plist-location/219584#219584 and, after copying the new version of the qutebrowser.app package, the OS recognizes QB as a "possible browser" (and defaulbrowser works).

Can you try achieving the same result by editing the qutebrowser.spec file according to the PyInstaller docs and rebuilding the .app via tox -e pyinstaller? Then you could do a PR with those changes and get them into qutebrowser.

But QB still doesn't handle opened files (like .jpg s)

I don't understand what you mean. Opened from where, how?

or piped urls (I use Karabiner to open several pages)

I'm not sure what Karabiner does, but I'm pretty sure it doesn't pipe stuff to an application.

or even "drag-n-drop-over-the-icon"

No idea how that works on OS X...

m2habert commented 8 years ago

Can you try achieving the same result by editing the qutebrowser.spec file according to the PyInstaller docs and rebuilding the .app via tox -e pyinstaller? Then you could do a PR with those changes and get them into qutebrowser.

I could try, but bear in mind I have zero knowledge of Python and related. Never heard of tox, etc. I've just installed pip27 (thru MacPorts) trying to make the umpv script work: ¿is it all it takes to install tox?

I don't understand what you mean. Opened from where, how?

I set all image files to be opened by the default browser (all the features provided by Vimperator lead to me using the browser as the main starting point in organizing and/or researching). When I try to do the same with QB, it doesn't work.

Also, in the MacOS interface one can save urls as files and, when clicked or pened etc, they open in the default browser. Don't really use them, but tested it just in case and QB does not respond.

Also, I use a launcher (LaunchBar) which stacks and works the clipboard following a similar logic: if a yanked url is on the clipboard history, upon pressing it opens on the default browser. Also can't make it work with QB.

Also, any hiperlynk in any text file fails to open in QB when clicked.

I'm not sure what Karabiner does, but I'm pretty sure it doesn't pipe stuff to an application.

Sorry, I forgot it was a platform specific project: it is a keyboard remapper. Maybe I'm using the wrong term: Karabiner can activate bash scripts either as external files or saved as string in its user profile file. But I mostly use it to open saved urls as to activate any saved page from any place / program by hitting a personal shortcut.

Again, such url would be opened by the default browser, but QB is not "complying".

No idea how that works on OS X...

On OS any icon representing a file can be dragged by the mouse and dropped over the application icon. If said app can open the file, it will. I tried QB with urls, jpgs, pdfs, txts, all unsuccesfuly.

The-Compiler commented 8 years ago

Okay - let's start with it being settable as default browser first, and then maybe figure out the rest from there.

Yeah, you should be able to do pip install tox and then run tox -e pyinstaller, though I'm not sure if you need to adjust your $PATH for MacPorts stuff first.

On OS any icon representing a file can be dragged by the mouse and dropped over the application icon. If said app can open the file, it will. I tried QB with urls, jpgs, pdfs, txts, all unsuccesfuly.

Yeah, I mean how it works internally, i.e. how OS X calls the application. I have a feeling that this isn't related to the default browser stuff above, but is a separate mechanism.

m2habert commented 7 years ago

Can you try achieving the same result by editing the qutebrowser.spec file according to the PyInstaller docs and rebuilding the .app via tox -e pyinstaller? Then you could do a PR with those changes and get them into qutebrowser.

I would like to try to help with that today, but I have no idea if it is now redundant with the progress of #1692

¿Should I follow @edrex steps and try to build a QB version with the qtWebEngine backend first? (I could be way off, sorry)

The-Compiler commented 7 years ago

I don't see how #1692 would make this redundant :wink:

Setting up Qt with QtWebKit like mentioned in https://github.com/The-Compiler/qutebrowser/pull/2049/files would be the first step - however, since @edrex already has some experience with PyInstaller and a working development environment, maybe he wants to take a look? :wink:

m2habert commented 7 years ago

I'll plus 1 that faster than you can say "useless ignorant newbie". 😉

(thanks in advance, @edrex )

The-Compiler commented 7 years ago

Please don't call yourself useless or ignorant - your experiments with a modified spec file and other ways of invoking qutebrowser are very useful information!

The-Compiler commented 7 years ago

So apparently it's not possible to generate plist files with more complex types from PyInstaller.

I modified build_release.py to copy a fixed Info.plist:

diff --git a/misc/qutebrowser.spec b/misc/qutebrowser.spec
index 81983aa..438105a 100644
--- a/misc/qutebrowser.spec
+++ b/misc/qutebrowser.spec
@@ -69,7 +69,4 @@ coll = COLLECT(exe,

 app = BUNDLE(coll,
              name='qutebrowser.app',
-             icon=icon,
-             info_plist={'NSHighResolutionCapable': 'True'},
-             # https://github.com/pyinstaller/pyinstaller/blob/b78bfe530cdc2904f65ce098bdf2de08c9037abb/PyInstaller/hooks/hook-PyQt5.QtWebEngineWidgets.py#L24
-             bundle_identifier='org.qt-project.Qt.QtWebEngineCore')
+             icon=icon)
diff --git a/scripts/dev/build_release.py b/scripts/dev/build_release.py
index 03ef4c7..5d108b8 100755
--- a/scripts/dev/build_release.py
+++ b/scripts/dev/build_release.py
@@ -96,6 +96,9 @@ def build_osx():
     update_3rdparty.update_pdfjs()
     utils.print_title("Building .app via pyinstaller")
     call_tox('pyinstaller', '-r')
+    plist = os.path.join('dist', 'qutebrowser.app', 'Contents', 'Info.plist')
+    os.remove(plist)
+    shutil.copy(os.path.join('misc', 'Info.plist'), plist)
     utils.print_title("Building .dmg")
     subprocess.check_call(['make', '-f', 'scripts/dev/Makefile-dmg'])
     utils.print_title("Cleaning up...")

And added this misc/Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleShortVersionString</key>
  <string>0.0.0</string>
  <key>CFBundlePackageType</key>
  <string>APPL</string>
  <key>NSHighResolutionCapable</key>
  <string>True</string>
  <key>CFBundleURLTypes</key>
  <array>
    <dict>
      <key>CFBundleURLName</key>
      <string>http URL</string>
      <key>CFBundleURLSchemes</key>
      <array>
        <string>http</string>
      </array>
    </dict>
    <dict>
      <key>CFBundleURLName</key>
      <string>Secure http URL</string>
      <key>CFBundleURLSchemes</key>
      <array>
          <string>https</string>
      </array>
    </dict>
  </array>
  <key>CFBundleName</key>
  <string>qutebrowser</string>
  <key>CFBundleDisplayName</key>
  <string>qutebrowser</string>
  <key>CFBundleInfoDictionaryVersion</key>
  <string>6.0</string>
  <key>CFBundleIconFile</key>
  <string>qutebrowser.icns</string>
  <!-- https://github.com/pyinstaller/pyinstaller/blob/b78bfe530cdc2904f65ce098bdf2de08c9037abb/PyInstaller/hooks/hook-PyQt5.QtWebEngineWidgets.py#L24 -->
  <key>CFBundleIdentifier</key>
  <string>org.qt-project.Qt.QtWebEngineCore</string>
  <key>LSBackgroundOnly</key>
  <string>0</string>
  <key>CFBundleExecutable</key>
  <string>MacOS/qutebrowser</string>
</dict>
</plist>

However I still can't select qutebrowser in Settings -> General -> Default web browser.

@m2habert can you please share the info.plist file you have?

edrex commented 7 years ago

i played around with manually creating a plist too and couldn't ever get qutebrowser to show up in the dropdown. @m2habert thanks for your research, +1 sharing plist

The-Compiler commented 7 years ago

FWIW with "can't select" I do mean "it doesn't show up at all"

m2habert commented 7 years ago

I'm not sure now that my attempts at a "fixed" plist granted instant browser-able recognition by the OS:

I either had to at the end make a copy of the QB.app to some other directory (thus prompting the OS to regenerate whatever classification it previously setted for the bundle), or

had to use the https://github.com/kerma/defaultbrowser (suggested by @mrjovanovic).

Maybe even had to do both; can't remember.

(in any case:

modified Firefox plist

QB's orginal + arrays suggested by stackoverflow post mentioned above

)

m2habert commented 7 years ago

Hi there @edrex , hi there @The-Compiler !

¿Did my previous comment help in anyway? Did you manage to advance on the matter in any way?

Any news would be greatly appreciated (not having QB as the default browser ends up being a big hindrance for me)

Thanks.

Hylian commented 7 years ago

I tried setting qutebrowser as the default browser in Windows 10 by manually editing the registry following this documentation, but was unable to get it working. I'll try looking into it more when I have time.

Side note: Windows 10 doesn't allow manually setting the default browser through the registry anymore, as the setting is verified with a hash to ensure the user has set it through the Settings app. If the browser is registered properly, it should show up as an option for a default program.

drselump14 commented 7 years ago

https://github.com/kerma/defaultbrowser doesn't list the qutebrowser as optional browser in my case .. don't waste your time with it ...

ccryx commented 7 years ago

FYI, I'm on Windows 7 x64 and I adapted chrlauncher's SetDefaultBrowser.bat to set qutebrowser as my default browser which also registers the browser in the default program dialog (not sure what it's called in english).

The-Compiler commented 7 years ago

@ccryx Interesting! Can you share the modified .bat?

ccryx commented 7 years ago

@The-Compiler sure thing. There's also a RegistryCleaner.reg which undoes the changes. I've attached both to this post.

For the batch file to work it needs to be in the same directory as qutebrowser.exe or adapted to point to the right path.

setqutebrowserdefault.bat.txt

RegistryCleaner.reg.txt

ghost commented 7 years ago

So, how do I set qutebrowser as the default on mac?

m2habert commented 7 years ago

Still no solution... (I've been using karabiner for automating yank from FFx >> sel qb @Dock >> paste @qb )

ghost commented 7 years ago

@m2habert How exactly does that work?

m2habert commented 7 years ago

It's not exactly the cleanest of solutions: karabiner is a keyboard customization tool that may be set up to convert shortcut whatever under application whatever into keystrokes so and so... So I mapped gx to y (Vimperator's yank) + d (delete) + focus the Dock + q + u + t for selecting qutebrowser + RETURN + pw (my mapping for "paste in a new window").

Check it out : https://github.com/tekezo/Karabiner/

ghost commented 7 years ago

@The-Compiler So, for now, there is no clear solution to make it the default browser. However, I have come up with a way to do so by doing 2 combinations:

  1. I do all my searches in alfred. So, instead I overroed the default callback to copy the query to the clipboard and then call keyboard maestro via a keyboard shortcut that alfred executed.
  2. For the rest, I managed to have iterm2 be the 'default browser' for https, and then I can bind an iterm2 profile to handle https and run the query into the qutebrowser script.

I know both methods might seem convoluted, but until a way is found to have the .app file actually be the default browser, I have achieved a semblant of default browser using these hacks!

Let me know if you want me to document this more somewhere in the wiki.

@m2habert the problem is that Karabiner is outdated and replaced by something else that doens't do the job properly. Hence why I ended up using keyboard maestro (which is very powerful btw).

m2habert commented 7 years ago

@piotryordanov Wasn't aware of this (since I did not move up from El Capitan OS), but chances are that the temp Karabiner do most of the main stuff. Anyway, I suggest you keep checking it up as Karabiner is a more open and complete solution than Maestro.

khinsen commented 7 years ago

Here's a workaround for macOS.

1) Launch the "Script Editor" app that comes with macOS. Paste in the three line script

on open location this_url
    do shell script "/Applications/qutebrowser.app/Contents/MacOS/qutebrowser " & this_url
end open location

If your qutebrowser is somewhere else than under /Applications, adapt the path. Save this as qutelauncher.scpt, then export as an Application qutelauncher.app.

2) Edit the file qutelauncher.app/Contents/Info.plist, adding the block

    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>Web site URL</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>http</string>
                <string>https</string>
            </array>
        </dict>
        <dict>
            <key>CFBundleURLName</key>
            <string>Local file URL</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>file</string>
            </array>
        </dict>
    </array>

just before the final two lines which should be

</dict>
</plist>

3) Move qutelauncher.app to /Applications

At this point, you can already use the macOS open command:

open -a qutelauncher http://my-site.org/

According to all documentation I have found on this topic, you should also be able to select qutelauncher as the default browser (System Preferences, "General" pane). But for me this didn't work, it's simply not in the list to choose from. So I went the manual way:

4) Edit ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist (after making a backup of course!) This requires first converting the file to xml format:

plutil -convert xml1~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist`

In that file, you will see the bundle id of your current default browser (for me org.mozilla.firefox in a few places: for http, https, public.html, and perhaps more. Replace all these by the bundle id of your qutelauncher app, which you can find in the Info.plist you edited in step 2. For me this is com.apple.ScriptEditor.id.qutelauncher.

5) Restart your computer.

Final notes:

The-Compiler commented 7 years ago

Wait - so macOS doesn't allow you to just set something as URL handler, and then opens that with the selected URL as argument? What a can of worms... 😟

khinsen commented 7 years ago

macOS apps never get command line arguments. There is a different, and more flexible, information passing system via "events". I suspect this pre-dates macOS X, (i.e. comes from the non-Unix original Macintosh) but I don't really know the history.

When you do something like "open -a qutebrowser some-page.html" from the command line, the app gets launched without command line arguments, and is sent an "open" event immediately afterwards.

My vague memories of playing with Qt in the past tell me that Qt actually handles these events and passes them on as Qt events, so handling URL open events in qutebrowser should not be very much work.

Perhaps this reference is of help: http://doc.qt.io/qt-4.8/qfileopenevent.html

residentsummer commented 7 years ago

I've stumbled upon this python project that implements URL events handling. Though I'm not sure if it'll work with PyQT and PyInstaller stuff...

Is there a quick way I can tweak the launch script of the qutebrowser I've downloaded from Releases? Because the last time I've tried to build it from source (half a year ago?), I've failed miserably on app bundle generation with tox/pyinstaller. Not to mention centuries wasted while qt was building... :/

The-Compiler commented 7 years ago

I have no idea whether you can modify it - I think there's a library.zip or so in the .dmg, but I have no idea how PyInstaller really works internally.

FWIW, you can install Qt via Homebrew without having to build it from sources AFAIK.

From a quick look at what Qt has, looks like there's QFileOpenEvent which has an url() member, so I guess that's being sent with URLs as well. I guess qutebrowser can handle that, the remaining question (apart from implementing it) is how it'd know it gets launched to get an event later, so it doesn't have to open e.g. the homepage...

residentsummer commented 7 years ago

IIRC at that time I had to build Qt from source because of QtWebKit/QtWebEngine transition, the version from Homebrew was incompatible or something... Should try to build the qutebrowser again after all.

The-Compiler commented 7 years ago

Ah, right, that probably was when qutebrowser required QtWebKit to run (it doesn't anymore), and Homebrew already dropped it.

m2habert commented 7 years ago

Regarding @khinsen 's workaround, step 4:

https://github.com/kerma/defaultbrowser worked for me, no need to restart (skipped steps 4 & 5)

defaultbrowser -set qutelauncher

(thanks again, @khinsen !) (I'm on El Cap -- OS X 10.11.6)