Skip to content

Commit

Permalink
deploy: 17169dc
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand committed Jul 10, 2024
1 parent 223b59c commit 43186a8
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 94 deletions.
8 changes: 4 additions & 4 deletions assets/css/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions binding_call.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package playwright

import (
"fmt"
"strings"

"github.com/go-stack/stack"
)

type BindingCall interface {
Call(f BindingCallFunction)
}
Expand Down Expand Up @@ -57,6 +64,22 @@ func (b *bindingCallImpl) Call(f BindingCallFunction) {
}
}

func serializeError(err error) map[string]interface{} {
st := stack.Trace().TrimRuntime()
if len(st) == 0 { // https://github.com/go-stack/stack/issues/27
st = stack.Trace()
}
return map[string]interface{}{
"error": &Error{
Name: "Playwright for Go Error",
Message: err.Error(),
Stack: strings.ReplaceAll(strings.TrimFunc(fmt.Sprintf("%+v", st), func(r rune) bool {
return r == '[' || r == ']'
}), " ", "\n"),
},
}
}

func newBindingCall(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *bindingCallImpl {
bt := &bindingCallImpl{}
bt.createChannelOwner(bt, parent, objectType, guid, initializer)
Expand Down
13 changes: 0 additions & 13 deletions js_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"math/big"
"net/url"
"reflect"
"runtime/debug"
"strings"
"time"
)

Expand Down Expand Up @@ -308,17 +306,6 @@ func serializeArgument(arg interface{}) interface{} {
}
}

func serializeError(err error) map[string]interface{} {
stack := strings.Split(string(debug.Stack()), "\n")
return map[string]interface{}{
"error": &Error{
Name: "Playwright for Go Error",
Message: err.Error(),
Stack: strings.Join(stack[:len(stack)-5], "\n"),
},
}
}

func newJSHandle(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *jsHandleImpl {
bt := &jsHandleImpl{
preview: initializer["preview"].(string),
Expand Down
23 changes: 22 additions & 1 deletion tests/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestBrowserContextExposeBindingPanic(t *testing.T) {
innerError := result.(map[string]interface{})
require.Equal(t, innerError["message"], "WOOF WOOF")
stack := strings.Split(innerError["stack"].(string), "\n")
require.Contains(t, stack[len(stack)-1], "binding_test.go")
require.Contains(t, stack[3], "binding_test.go")
}

func TestBrowserContextExposeBindingHandleShouldWork(t *testing.T) {
Expand All @@ -102,3 +102,24 @@ func TestBrowserContextExposeBindingHandleShouldWork(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 42, res)
}

func TestPageExposeBindingPanic(t *testing.T) {
BeforeEach(t)

err := page.ExposeBinding("woof", func(source *playwright.BindingSource, args ...interface{}) interface{} {
panic(errors.New("WOOF WOOF"))
})
require.NoError(t, err)
result, err := page.Evaluate(`async () => {
try {
await window['woof']();
} catch (e) {
return {message: e.message, stack: e.stack};
}
}`)
require.NoError(t, err)
innerError := result.(map[string]interface{})
require.Equal(t, innerError["message"], "WOOF WOOF")
stack := strings.Split(innerError["stack"].(string), "\n")
require.Contains(t, stack[3], "binding_test.go")
}
2 changes: 1 addition & 1 deletion tests/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestBrowserNewContext(t *testing.T) {
}

func TestBrowserNewContextWithExtraHTTPHeaders(t *testing.T) {
context, page = newBrowserContextAndPage(t, playwright.BrowserNewContextOptions{
BeforeEach(t, playwright.BrowserNewContextOptions{
ExtraHttpHeaders: map[string]string{"extra-http": "42"},
})

Expand Down
Loading

0 comments on commit 43186a8

Please sign in to comment.