Skip to content

Is there a way to watch for element updates within an element? #1048

Answered by ysmood
atye asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can use the proto lib to do it. The js code is copied from MDN:

// Package main ...
package main

import (
	"fmt"

	"github.com/go-rod/rod"
	"github.com/go-rod/rod/lib/utils"
	"github.com/ysmood/gson"
)

func main() {
	page := rod.New().MustConnect().MustPage("http://example.com").MustWaitStable()

	page.MustExpose("myChanged", func(j gson.JSON) (interface{}, error) {
		fmt.Println("dom changed", j.JSON("", "  "))

		return nil, nil
	})

	page.MustElement("h1").MustEval(`() => {
		// Options for the observer (which mutations to observe)
		const config = { attributes: true, childList: true, subtree: true };
		
		// Callback function to execute when mutations are observed
		const c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by atye
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants