Issue 24241: webbrowser default browser detection and/or public API for _trylist. (original) (raw)

Created on 2015-05-19 13:43 by daves, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
preferredbrowser.diff daves,2015-07-18 01:03 Prioritize the default desktop browser review
Pull Requests
URL Status Linked Edit
PR 85 merged daves,2017-02-18 12:56
PR 288 merged ncoghlan,2017-02-25 07:49
PR 342 merged berker.peksag,2017-02-27 14:40
Messages (14)
msg243590 - (view) Author: David Steele (daves) * Date: 2015-05-19 13:43
When calling webbrowser.open*(), the module goes through a list of installed browsers, and uses the first one that succeeds, to process the request. The first 'browsers' in the 'X' list are 'xdg-open' and others of that ilk. The problem is that they only have one 'open' behavior - the 'new' parameter is ignored ('same window', 'new window', 'new tab'). I can get the fully supported default browser in GNOME with e.g. def browser(): app = Gio.app_info_get_default_for_type('x-scheme-handler/https', True) bpath = app.get_filename() for candidate in webbrowser._tryorder: if candidate in bpath: return webbrowser.get(using=candidate) return webbrowser.get() ... but this code accesses a private list. The problems are: 1) webbrowser does not determine and return the current default browser. 2) There is no public interface for determining the current/installed browser type list. The problem can be mitigated by resolving (1) and/or (2). Also, the browser type list in the documentation is missing many entries. Checked on 2.7 and 3.4. I believe this is valid across all supported versions.
msg243593 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-19 14:19
Any change is going to be an enhancement, so it will only go in 3.6 (at this point...beta/feature freeze for 3.5 is this weekend). Would you like to propose a patch?
msg243598 - (view) Author: David Steele (daves) * Date: 2015-05-19 14:43
On Tue, May 19, 2015 at 10:19 AM, R. David Murray <report@bugs.python.org> wrote: ... > Would you like to propose a patch? My preferred solution would be a bit intrusive - check for and use xdg-settings or gi.repository.Gio to identify the default browser, and match the result against the type list. I'm not sure that would get approval, nor am I sure of the best standard-library-compliant way to go about it.
msg246874 - (view) Author: David Steele (daves) * Date: 2015-07-18 01:03
Patch attached, to sort the desktop default browser to the top of _tryorder.
msg287731 - (view) Author: David Steele (daves) * Date: 2017-02-14 02:57
See https://github.com/python/cpython/pull/85
msg288077 - (view) Author: Jaysinh shukla (jaysinh.shukla) * Date: 2017-02-18 13:04
Hello David, I hope you are still working on https://github.com/python/cpython/pull/85 I tried to add few suggestions. Please write back on any confusions. Thanks!
msg288078 - (view) Author: David Steele (daves) * Date: 2017-02-18 13:11
Jaysinh, Thanks for the feedback. I'm adding the documentation now. As I noted in github, I'm not sure what the preferred exception handling would be for xdg-settings.
msg288539 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017-02-25 05:00
To summarise the changes that were made during the PR review, here's the eventual commit message for the merged PR: ============ bpo-24241: Improve preferred webbrowser handling (#85) - Add 'preferred' argument to webbrowser.register - Use xdg-settings to specify preferred X browser The first change replaces the existing undocumented tri-state 'try_order' parameter with the documented boolean keyword-only 'preferred' parameter. Setting it to True places the browser at the front of the list, preferring it as the return to a subsequent get() call. The second change adds a private `_os_preferred_browser` setting and then uses that to make the default browser reported by `xdg-settings` first in the try list when running under X (or another environment that sets the `DISPLAY` variable). This avoids the problem where the first entry in the tryorder queue otherwise defaults to xdg-open, which doesn't support the "new window" option. ============
msg288541 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017-02-25 05:45
After merging this, I belatedly realised that codecov's complaint about the lack of code coverage for the diff was actually valid: now that "preferred" is a public API, it should have a cross-platform test case. That should be a fairly straightforward test to write, as it can just use an arbitrary string, and then poke around in _tryorder directly to make sure it is updated as expected - it doesn't need to use a valid browser reference.
msg288550 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017-02-25 08:15
Second PR merged with the missing test case.
msg290366 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-03-24 23:37
New changeset 370f7a956cef5895c93ca5a53fc26b04df973aaf by Berker Peksag in branch 'master': bpo-24241: Add versionchanged directive to the documentation (#342) https://github.com/python/cpython/commit/370f7a956cef5895c93ca5a53fc26b04df973aaf
msg290401 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017-03-24 23:46
New changeset 56a8eccc43c66ae51c5a6bfc89635b1998fd419e by Nick Coghlan in branch 'master': bpo-24241: Add dedicated webbrowser.register test case (#288) https://github.com/python/cpython/commit/56a8eccc43c66ae51c5a6bfc89635b1998fd419e
msg290404 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2017-03-24 23:46
New changeset e3ce69522ffd7c0354d6e70d18f42bce325ed97e by Nick Coghlan (David Steele) in branch 'master': bpo-24241: Improve preferred webbrowser handling (#85) https://github.com/python/cpython/commit/e3ce69522ffd7c0354d6e70d18f42bce325ed97e
msg318167 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-05-30 11:23
It seems like this issue introduced a regression: bpo-33693.
History
Date User Action Args
2022-04-11 14:58:17 admin set github: 68429
2018-05-30 12:37:14 berker.peksag set pull_requests: - <pull%5Frequest1099>
2018-05-30 11:23:16 vstinner set nosy: + vstinnermessages: +
2017-03-31 16:36:38 dstufft set pull_requests: + <pull%5Frequest1099>
2017-03-24 23:46:59 ncoghlan set messages: +
2017-03-24 23:46:14 ncoghlan set messages: +
2017-03-24 23:37:01 berker.peksag set nosy: + berker.peksagmessages: +
2017-02-27 14:40:51 berker.peksag set pull_requests: + <pull%5Frequest296>
2017-02-25 08:15:11 ncoghlan set status: open -> closedmessages: + stage: test needed -> resolved
2017-02-25 07:49:29 ncoghlan set pull_requests: + <pull%5Frequest258>
2017-02-25 05:45:20 ncoghlan set assignee: ncoghlan
2017-02-25 05:45:02 ncoghlan set status: closed -> openmessages: + stage: resolved -> test needed
2017-02-25 05:00:33 ncoghlan set nosy: + ncoghlanmessages: +
2017-02-25 04:58:32 ncoghlan set status: open -> closedresolution: fixedstage: needs patch -> resolved
2017-02-18 13:11:21 daves set messages: +
2017-02-18 13:04:02 jaysinh.shukla set nosy: + jaysinh.shuklamessages: +
2017-02-18 12:56:44 daves set pull_requests: + <pull%5Frequest123>
2017-02-14 02:57:57 daves set messages: +
2015-07-18 01:03:44 daves set files: + preferredbrowser.diffkeywords: + patchmessages: +
2015-05-19 14:43:54 daves set messages: +
2015-05-19 14:19:09 r.david.murray set versions: + Python 3.6type: behavior -> enhancementnosy: + r.david.murraytitle: webbrowser (very often) doesn't support the 'new' parameter -> webbrowser default browser detection and/or public API for _trylist.messages: + stage: needs patch
2015-05-19 13:43:02 daves create