pkg / browser Goto Github PK
View Code? Open in Web Editor NEWPackage browser provides helpers to open files, readers, and urls in a browser window.
License: BSD 2-Clause "Simplified" License
Package browser provides helpers to open files, readers, and urls in a browser window.
License: BSD 2-Clause "Simplified" License
Currently, if browser.OpenURL
is invoked multiple times, it will open multiple tabs in the web browser. I'd like to be able to maintain a single invocation, whereby the tab is refreshed if it's already open.
Freebsd is unsupported, it need to run same openBrowser command than OpenBSD.
@davecheney Looks like #21 has cause a regression:
Error: ../../../go/pkg/mod/github.com/pkg/[email protected]/browser_unsupported.go:11:6: openBrowser redeclared in this block
previous declaration at ../../../go/pkg/mod/github.com/pkg/[email protected]/browser_linux.go:5:30
Error: ../../../go/pkg/mod/github.com/pkg/[email protected]/browser_unsupported.go:15:6: setFlags redeclared in this block
previous declaration at ../../../go/pkg/mod/github.com/pkg/[email protected]/browser_linux.go:9:20
Error: Process completed with exit code 2.
Is this project dead? I see no commits since September 2021. Consider deprecating and linking to fork https://github.com/cli/browser which is actively developed.
https://go.dev/ref/mod#go-mod-file-module
To deprecate a module, an author may add a // Deprecated: comment and tag a new release. The author may change or remove the deprecation message in a higher release.
Hi
I try to build with solaris but i have this error
../../pkg/mod/github.com/pkg/[email protected]/browser_unsupported.go:7:2: imported and not used: "os/exec"
Hello,
Would it be possible to open the browser with data: URL on Windows? I want to display an image, so have something like data:image/png;base64,...
. If I manually paste it in browser address bar (Edge, Firefox, Chrome) it shows the image correctly, but when I execute the command from my go program it pops up "You'll need a new app to open this data" dialog.
Logging things in packages is not the Go way of doing things. the package should never log anything or at least have a way to disable it. IE i get these logs when I use the package on Debian
"Icon theme "gnome" not found.
Icon theme "ubuntu-mono-dark" not found.
Icon theme "Mint-X" not found.
Icon theme "elementary" not found.
Icon theme "gnome" not found."
Could we get a semantic versioning release for this project :)
On many linux systems, the BROWSER
environment variable allows users to specify their default browser, much like the EDITOR
or PAGER
environment variables.
Would you be open to a PR that adds support for a browser parameter and/or environment variable? I'm happy to contribute Windows and MacOS support for these.
I use it like this:
request, err := http.NewRequest("POST", login_url, strings.NewReader(formData.Encode()))
if err != nil {
return err
}
request.Header.Set("Referer", login_url)
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
response, err := client.Do(request)
if err != nil {
return err
}
fmt.Printf("status code POST: %d\n", response.StatusCode)
browser.OpenReader(response.Body)
The file /tmp/browser.1293014077.html
contains the html.
But the browser seems to not find the file.
I use Chromium on Ubuntu Linux
Howdy all y'all,
My Pixel 5a running Android 13 cannot find a web browser.
My Android browser is NOT one of these (xdg-open chrome google-chrome firefox). I get something like these messages:
'fails exec: "xdg-open": executable file not found in $PATH'
'fails exec: "chrome": executable file not found in $PATH'
'fails exec: "google-chrome": executable file not found in $PATH'
'fails exec: "firefox": executable file not found in $PATH'
Does anyone know what it is?
I look forward to hearing from you,
Dale
I see you've switched to go modules by adding go.mod
. Could you now release a semver-formatted version of this library? I think that's as easy as git tag v1.0.0
and pushing.
Tagging a semantic version simplifies packaging on Linux, which in turn simpifies packaging applications that depend on this library. Please tag say v0.1.0.
This is a very popular library, but it isn't packaged in many Linux distributions https://repology.org/project/go:github-pkg-browser/versions
The current Windows incarnation is brittle:
Lines 9 to 12 in 0a3d74b
it survives ampersands, but not other characters:
package main
import "github.com/pkg/browser"
func main() {
browser.OpenURL("http://example.com?aa bb&cc")
}
better would be to call RunDLL32, no replacer needed. Examples:
rundll32 url,OpenURL "http://example.com?aa bb&cc"
rundll32 url,FileProtocolHandler "http://example.com?aa bb&cc"
https://github.com/skratchdot/open-golang/blob/master/open/exec_windows.go
Or call browser directly via the BROWSER environment variable. This is what
Python does:
import webbrowser
webbrowser.open('http://example.com?aa bb&cc')
https://github.com/python/cpython/blob/master/Lib/webbrowser.py
Or better still would be to call ShellExecuteW
on Windows:
https://docs.microsoft.com/windows/win32/api/shellapi/nf-shellapi-shellexecutew
This is what D does:
import std.process;
void main() {
browse("http://example.com?aa bb&cc");
}
https://github.com/dlang/phobos/blob/master/std/process.d
and Nim:
import browsers
openDefaultBrowser("http://example.com?aa bb&cc")
https://github.com/nim-lang/Nim/blob/devel/lib/pure/browsers.nim
๐๐ป
I installed this package, and ran it once and it worked fine. I then came back and tried it again (after making some code changes) and found that no matter what URL I provided to browser.OpenURL
the function would error with...
NOTE: I've broken it up over multiple lines for readability.
The application cannot be opened for an unexpected reason, error=
Error Domain=NSOSStatusErrorDomain
Code=-600 "procNotFound: no eligible process with specified descriptor"
UserInfo={_LSLine=379, _LSFunction=_LSAnnotateAndSendAppleEventWithOptions}
I've failed to find much useful information on this,
but there is a long thread from another project (which may or may not be useful):
lwouis/alt-tab-macos#704
When compiled with -ldflags "-H windowsgui"
, browser.OpenURL
does not work at all.
I am attempting to open a local file in the browser on Windows with a fragment that specifies the document location. For example: c:\some-file.html#basic
. The file opens fine, but the #basic
part is ignored. I tried this with both OpenFile and OpenURL (absolute path with prepending "file://"), but neither seem to work.
Please update the "unsupported" case to be more useful. You could provide a browser.IsSupported() that returns true
only on supported platforms.
I find the use of build-time handling of different platforms to be overly complex. After reviewing this module and considering writing a pull request, I just went with:
func openBrowser(url string) {
cmd := "xdg-open"
args := []string{url}
switch runtime.GOOS {
case "darwin":
cmd = "open"
case "windows":
cmd = "rundll32"
args = []string{"url.dll,FileProtocolHandler", url}
}
err := exec.Command(cmd, args...).Start()
if err == nil {
return
}
fmt.Printf("Failed to launch %s: %v", cmd, err)
fmt.Printf("Load this URL in your browser:\n %s\n", url)
}
because it could work on more types of Unix systems and more gracefully fails when assumptions are not met.
Adding support for the BROWSER environment variable to that would be even better.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.