Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eval erorr: {-32000 Object reference chain is too long } #708

Closed
kurimi1 opened this issue Sep 1, 2022 · 3 comments
Closed

Eval erorr: {-32000 Object reference chain is too long } #708

kurimi1 opened this issue Sep 1, 2022 · 3 comments
Labels
question Questions related to rod

Comments

@kurimi1
Copy link

kurimi1 commented Sep 1, 2022

Rod Version: v0.109.3

reference: puppeteer/puppeteer#2746

url: http://123.120.53.141:8181/
js:

webix

inchrome:
image

The code to demonstrate your question

func Test_Evel(t *testing.T) {
	paramURL := "http://123.120.53.141:8181/"
	l := launcher.MustNewManaged("").Headless(true)
	Browser := rod.
		New().
		Client(l.MustClient()).
		MustConnect().
		MustIgnoreCertErrors(true)
	Page := Browser.MustIncognito().MustPage()
	errRod := rod.Try(func() {
		Page.
			Timeout(30 * time.Second).
			MustNavigate(paramURL)
	})
	if errRod != nil {
		logrus.Errorf("Error while visiting %s : %s", paramURL, errRod.Error())

		return
	}
	errRod = rod.Try(func() {
		Page.
			Timeout(30 * time.Second).
			MustWaitLoad()
	})
	if errRod != nil {
		logrus.Errorf("Error while loading %s : %s", paramURL, errRod.Error())

		return
	}
	jsProp := "webix"
	res, err := Page.Eval("() =>" + jsProp)
	if err == nil && res != nil && res.Value.Val() != nil {
		value := ""
		if res.Type == "string" || res.Type == "number" {
			value = res.Value.String()
		}
		logrus.Info(value)
		return
	} else {
		logrus.Error("js eval error:", err)
		return
	}
}
time="2022-09-01T08:22:46Z" level=error msg="js eval error:{-32000 Object reference chain is too long }"
@kurimi1 kurimi1 added the question Questions related to rod label Sep 1, 2022
@rod-robot
Copy link

Please fix the format of your markdown:

6:4 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
7 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```js"]
9 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
60 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
61 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
61 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
65 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
66 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 3]

generated by check-issue

@kurimi1
Copy link
Author

kurimi1 commented Sep 1, 2022

same site
js:

jQuery.pjax

chrome:
image

rod err:

\u003cnil\u003e

what is it ?

@ysmood
Copy link
Member

ysmood commented Sep 3, 2022

It's because the object is too big for chrome to serialize it into a JSON string.

For example, run the code below in the devtools console:

let a = {};
a.b = a;
JSON.stringify(a);

You will get this error:

Uncaught TypeError: Converting circular structure to JSON

But you can still get the huge object's reference with Rod and fetch its properties like this test case:

rod/page_eval_test.go

Lines 285 to 304 in 0acf6e2

func TestEvalObjectReferenceChainIsTooLong(t *testing.T) {
g := setup(t)
p := g.page.MustNavigate(g.blank())
obj, err := p.Evaluate(&rod.EvalOptions{
JS: `() => {
let a = {b: 1}
a.c = a
return a
}`,
})
g.E(err)
_, err = p.Eval(`a => a`, obj)
g.Eq(err.Error(), "{-32000 Object reference chain is too long }")
val := p.MustEval(`a => a.c.c.c.c.b`, obj)
g.Eq(val.Int(), 1)
}

About \u003cnil\u003e, just use the js to log it, such as console.log("\u003cnil\u003e") It's the standard way to fmt.Print values in golang.

@ysmood ysmood closed this as completed Sep 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

3 participants