Skip to content

Commit 0c7bc12

Browse files
committed
fix iframe OOPIF issue
Resolve #548
1 parent 810b257 commit 0c7bc12

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"onclick",
9696
"onmouseenter",
9797
"onmouseout",
98+
"OOPIF",
9899
"opencontainers",
99100
"osversion",
100101
"progresser",

element_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"image/color"
99
"image/png"
10+
"net"
1011
"os"
1112
"path/filepath"
1213
"testing"
@@ -16,6 +17,7 @@ import (
1617
"github.com/go-rod/rod/lib/cdp"
1718
"github.com/go-rod/rod/lib/devices"
1819
"github.com/go-rod/rod/lib/input"
20+
"github.com/go-rod/rod/lib/launcher"
1921
"github.com/go-rod/rod/lib/proto"
2022
"github.com/go-rod/rod/lib/utils"
2123
"github.com/ysmood/gson"
@@ -263,6 +265,37 @@ func TestIframes(t *testing.T) {
263265
g.True(frame02.MustHas("[a=ok]"))
264266
}
265267

268+
func TestIframeCrossDomains(t *testing.T) {
269+
g := setup(t)
270+
271+
r1 := g.Serve()
272+
r2 := g.Serve()
273+
274+
// Same domain name with different ports won't trigger OOPIF (out-of-process iframes)
275+
// To check the page OOPIF status, you can use chrome://process-internals tab in the browser.
276+
host1 := net.JoinHostPort("localhost", r1.HostURL.Port())
277+
host2 := net.JoinHostPort("127.0.0.1", r2.HostURL.Port())
278+
279+
u1 := fmt.Sprintf("http://%s/iframe", host1)
280+
u2 := fmt.Sprintf("http://%s/page", host2)
281+
282+
r1.Route("/iframe", ".html", `<html>
283+
<div id="a">a</div>
284+
</html>`)
285+
286+
r2.Route("/page", ".html", `<html>
287+
<iframe sandbox src="`+u1+`"></iframe>
288+
</html>`)
289+
290+
u := launcher.New().HeadlessNew(true).MustLaunch()
291+
browser := rod.New().ControlURL(u).NoDefaultDevice().MustConnect()
292+
defer browser.MustClose()
293+
294+
page := browser.MustPage(u2)
295+
296+
g.Eq(page.MustElement("iframe").MustFrame().MustElement("#a").MustText(), "a")
297+
}
298+
266299
func TestContains(t *testing.T) {
267300
g := setup(t)
268301

lib/launcher/launcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func New() *Launcher {
8888
"disable-prompt-on-repost": nil,
8989
"disable-renderer-backgrounding": nil,
9090
"disable-sync": nil,
91+
"disable-site-isolation-trials": nil,
9192
"enable-automation": nil,
9293
"enable-features": {"NetworkService", "NetworkServiceInProcess"},
9394
"force-color-profile": {"srgb"},

lib/launcher/launcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func TestLaunchUserMode(t *testing.T) {
121121
Revision(launcher.RevisionDefault).
122122
Logger(io.Discard).
123123
Leakless(false).Leakless(true).
124-
Headless(false).Headless(true).RemoteDebuggingPort(port).
125124
HeadlessNew(true).HeadlessNew(false).
125+
Headless(false).Headless(true).RemoteDebuggingPort(port).
126126
NoSandbox(true).NoSandbox(false).
127127
Devtools(true).Devtools(false).
128128
StartURL("about:blank").

0 commit comments

Comments
 (0)