Skip to content

Commit

Permalink
fix iframe OOPIF issue
Browse files Browse the repository at this point in the history
Resolve #548
  • Loading branch information
ysmood committed Jun 17, 2024
1 parent 810b257 commit 0c7bc12
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"onclick",
"onmouseenter",
"onmouseout",
"OOPIF",
"opencontainers",
"osversion",
"progresser",
Expand Down
33 changes: 33 additions & 0 deletions element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"image/color"
"image/png"
"net"
"os"
"path/filepath"
"testing"
Expand All @@ -16,6 +17,7 @@ import (
"github.com/go-rod/rod/lib/cdp"
"github.com/go-rod/rod/lib/devices"
"github.com/go-rod/rod/lib/input"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/proto"
"github.com/go-rod/rod/lib/utils"
"github.com/ysmood/gson"
Expand Down Expand Up @@ -263,6 +265,37 @@ func TestIframes(t *testing.T) {
g.True(frame02.MustHas("[a=ok]"))
}

func TestIframeCrossDomains(t *testing.T) {
g := setup(t)

r1 := g.Serve()
r2 := g.Serve()

// Same domain name with different ports won't trigger OOPIF (out-of-process iframes)
// To check the page OOPIF status, you can use chrome://process-internals tab in the browser.
host1 := net.JoinHostPort("localhost", r1.HostURL.Port())
host2 := net.JoinHostPort("127.0.0.1", r2.HostURL.Port())

u1 := fmt.Sprintf("http://%s/iframe", host1)
u2 := fmt.Sprintf("http://%s/page", host2)

r1.Route("/iframe", ".html", `<html>
<div id="a">a</div>
</html>`)

r2.Route("/page", ".html", `<html>
<iframe sandbox src="`+u1+`"></iframe>
</html>`)

u := launcher.New().HeadlessNew(true).MustLaunch()
browser := rod.New().ControlURL(u).NoDefaultDevice().MustConnect()
defer browser.MustClose()

page := browser.MustPage(u2)

g.Eq(page.MustElement("iframe").MustFrame().MustElement("#a").MustText(), "a")
}

func TestContains(t *testing.T) {
g := setup(t)

Expand Down
1 change: 1 addition & 0 deletions lib/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func New() *Launcher {
"disable-prompt-on-repost": nil,
"disable-renderer-backgrounding": nil,
"disable-sync": nil,
"disable-site-isolation-trials": nil,
"enable-automation": nil,
"enable-features": {"NetworkService", "NetworkServiceInProcess"},
"force-color-profile": {"srgb"},
Expand Down
2 changes: 1 addition & 1 deletion lib/launcher/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func TestLaunchUserMode(t *testing.T) {
Revision(launcher.RevisionDefault).
Logger(io.Discard).
Leakless(false).Leakless(true).
Headless(false).Headless(true).RemoteDebuggingPort(port).
HeadlessNew(true).HeadlessNew(false).
Headless(false).Headless(true).RemoteDebuggingPort(port).
NoSandbox(true).NoSandbox(false).
Devtools(true).Devtools(false).
StartURL("about:blank").
Expand Down

0 comments on commit 0c7bc12

Please sign in to comment.