mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-03 19:47:10 +00:00
Launch runs while the tab is still on about:blank, whose opaque origin denies storage access, so localStorage.clear() threw SecurityError and every web run died at launch. Storage.clearDataForOrigin needs no navigation. The exception helper lands here because "Uncaught" is what hid this for so long. Claude-Session: https://claude.ai/code/session_01Fj4wJUikdABuMQEETwW55J
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package chrome
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/chromedp/cdproto/runtime"
|
|
)
|
|
|
|
func TestSecurityOrigin(t *testing.T) {
|
|
cases := map[string]string{
|
|
"http://localhost:8088": "http://localhost:8088",
|
|
"http://localhost:5173/": "http://localhost:5173",
|
|
"https://app.example.com/a/b?c=d": "https://app.example.com",
|
|
"data:text/html,<body>hi</body>": "",
|
|
"file:///tmp/index.html": "",
|
|
"about:blank": "",
|
|
"": "",
|
|
"://not a url": "",
|
|
}
|
|
for target, want := range cases {
|
|
if got := securityOrigin(target); got != want {
|
|
t.Errorf("securityOrigin(%q) = %q, want %q", target, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestExceptionMessage_PrefersDescription pins the useful half of a page
|
|
// exception. ExceptionDetails.Text is "Uncaught" for every throw; the
|
|
// description is where the error a caller can act on lives.
|
|
func TestExceptionMessage_PrefersDescription(t *testing.T) {
|
|
withDescription := &runtime.ExceptionDetails{
|
|
Text: "Uncaught",
|
|
Exception: &runtime.RemoteObject{
|
|
Description: "SecurityError: Access is denied for this document.",
|
|
},
|
|
}
|
|
if got := exceptionMessage(withDescription); got != withDescription.Exception.Description {
|
|
t.Errorf("exceptionMessage = %q, want the description", got)
|
|
}
|
|
textOnly := &runtime.ExceptionDetails{Text: "Uncaught SyntaxError"}
|
|
if got := exceptionMessage(textOnly); got != "Uncaught SyntaxError" {
|
|
t.Errorf("exceptionMessage = %q, want the text fallback", got)
|
|
}
|
|
if got := exceptionMessage(nil); got != "" {
|
|
t.Errorf("exceptionMessage(nil) = %q, want empty", got)
|
|
}
|
|
}
|