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 129d90a commit f71a812
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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

0 comments on commit f71a812

Please sign in to comment.