Comments (3)
The following example worked on macOS. If it worked for you too, you may have placed the files in an insecure directory.
package main
import (
"log"
"os"
"path/filepath"
"github.com/pkg/browser"
)
func main() {
pathDirTmp, err := os.MkdirTemp(os.TempDir(), "sample_dir_*")
if err != nil {
log.Fatal(err)
}
pathFileTmp := filepath.Join(pathDirTmp, "sample_file.html")
dummyContent := `<html><body>Hello World2</body></html>`
// Create file under the temporary directory
if err := os.WriteFile(pathFileTmp, []byte(dummyContent), 0644); err != nil {
log.Fatal(err)
}
// Open the file in the browser
// if err := browser.OpenURL(pathFileTmp); err != nil {
// log.Fatal(err)
// }
// Open the file for reading
osFile, err := os.Open(pathFileTmp)
if err != nil {
log.Fatal(err)
}
// Consume the contents and present the results in a browser
if err := browser.OpenReader(osFile); err != nil {
log.Fatal(err)
}
// Open the directory of the temporary file
if err := browser.OpenURL(pathDirTmp); err != nil {
log.Fatal(err)
}
}
Env info
- Google Chrome v104.0.5112.101
- go version 1.18 and 1.19 (darwin/amd64)
from browser.
You said "you may have placed the files in an insecure directory"
But I am using it like this:
browser.OpenReader(response.Body)
This means, that I am not explicitly putting the content into a directory....
I had a look at how this gets handled by Python, but that's a huge file: https://github.com/python/cpython/blob/3.10/Lib/webbrowser.py
Sorry, I need to leave now. Feel free to close this, if you don't have time and energy.
from browser.
But I am using it like this:
browser.OpenReader(response.Body)
Yes yes, that's why the file pointer is passed like this.
osFile, err := os.Open(pathFileTmp) ** snip ** err := browser.OpenReader(osFile) ** snip **
My point was that "Where was the temp file created?"
The path "/tmp/browser.1293014077.html
" seems to be insecure. For example, on macOS, temporary files are created in private/var/folders
.
file:///private/var/folders/8c/lmckjks95fj4h_jqzw4v3k_w0000gn/T/browser.140875179.html
The /tmp/browser.1293014077.html
contained the response.Body
value, so it is assumed that the OS or the browser is blocking it for security reasons. Not sure.
Try using os.MkdirTemp()
and os.TempDir()
to store the value of response.Body
in a temporary directory. Then open it and look at the difference in paths.
Feel free to close this, if you don't have time and energy.
Unfortunately, I'm only a passer-by to help and don't have the privilege to close this issue.
from browser.
Related Issues (17)
- Console window appears when process is launched within Windows
- Allow caller to deal with failure HOT 1
- Stop using CMD with Windows HOT 1
- Refresh if URL is already open in browser HOT 5
- Package should not log anything by default HOT 1
- Add support for freebsd OS HOT 3
- Latest update has caused issue on linux HOT 1
- Release v1 HOT 5
- browser_unsupported error with build HOT 3
- Override browser? HOT 4
- Worked once then fails with low-level macOS error HOT 5
- OpenURL with data: URL
- My Pixel 5a running Android 13 cannot find a web browser? HOT 1
- Tag semantic version such as v0.1.0
- Deprecate dead project HOT 1
- browser.OpenURL does not work with windows GUI HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from browser.