Description
I get the following error in the console, referencing the compiled .js (which I will not post here because it's enormous:
Uncaught TypeError: Cannot read properties of undefined (reading 'onClicked') at Object.OnClicked (browser_action.go:82:3) at main (background.go:18:3) at $init (background.js:63510:9) at $goroutine (background.js:1690:21) at $runScheduled (background.js:1736:13) at $schedule (background.js:1760:9) at $go (background.js:1722:5) at background.js:63522:1 at background.js:63525:4
Commenting out the code that starts with, c.BrowserAction.OnClicked
allows the Extension to properly load, so it makes sense that there's something wrong with the OnClicked / maybe something GopherJS-related?
Simply commenting out the code in, "GetActiveWindowUrls" still results in the issue, to rule that out.
background.go
package main
import (
"github.com/fabioberger/chrome"
"TabUrls/helpers"
)
func main() {
helpers.GoosCheck()
var c = chrome.NewChrome()
c.BrowserAction.OnClicked(func(tab chrome.Tab) { // <-- issue here?
tabQuery := chrome.Object{
"currentWindow": true,
}
c.Tabs.Query(tabQuery, GetActiveWindowUrls)
})
}
func GetActiveWindowUrls(tabs []chrome.Tab) {
var c = chrome.NewChrome()
var urls []string
for _, value := range tabs {
urls = append(urls, value.Url)
}
c.Storage.Local.Set("tabUrls", urls)
createProps := chrome.Object{
"url": "urls.html",
}
c.Tabs.Create(createProps, func(tab chrome.Tab) {
updateProps := chrome.Object{
"active": true,
}
c.Tabs.Update(tab.Id, updateProps, func(tab chrome.Tab) {})
})
}
urls.go
package main
import (
"strings"
"github.com/fabioberger/chrome"
"honnef.co/go/js/dom"
"TabUrls/helpers"
)
var c = chrome.NewChrome()
var d = dom.GetWindow().Document()
func main() {
helpers.GoosCheck()
urls := c.Storage.Local.Get("tabUrls").Interface()
displayEl := d.GetElementByID("tabUrlsDisplay")
displayEl.SetTextContent(strings.Join(urls.([]string), "\n"))
}
helpers.go
package helpers
import (
"fmt"
"go/build"
)
func GoosCheck() {
if build.Default.GOOS == "windows" {
fmt.Print("GOOS is Windows. The GopherJS is falling back to GOOs=linux\n")
build.Default.GOOS = "linux"
}
}