amodm / webbrowser-rs

Rust library to open URLs in the web browsers available on a platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change `webbrowser::open` to call `open_with_url_and_target` instead of `open_with_url` to allow `target=_new`

vbeffa opened this issue · comments

Currently, if target_arch="wasm32", calls to webbrowser::open will open in the same tab/window, and there's no way to programmatically open a link in a new tab.

What should be the most appropriate behaviour here? opening using open_with_url_and_target with target as _blank?

Actually, I think it might be better to add a new function open_with_target that takes both the url and target as parameters. That way the signature of open doesn't need to change.

Here's a PR: #40

Unless there's a noticeable demand for open_with_target kind of behaviour, I'm not inclined to add a new function, as removals end up being tricky later.

I'm ok with the current behaviour of open_browser to default to a target of _blank (in case of wasm), or whatever makes it open a new tab, to make sure that it becomes consistent with how a lot of other browsers end up behaving.

But specifying a target programmatically will need more thought, and I wouldn't want to delay this change as I'm planning a release in the next few days.

@vbeffa I've modified the wasm code to open in _blank by default. This can be overridden by WEBBROWSER_WASM_TARGET env at compile time (the test uses this to set target to _self, for example).

The reason why I've kept it like this is because it's not possible to provide consistent behaviour as of now in selecting target names across different browsers. If there's a recurring demand for this, I'll revisit this choice.

This will go out in the next release (planned by end of this week).

@amodm thank you.