exposefunc

command
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Command exposefunc is a chromedp example demonstrating how to call Go functions from a page with chromedp.ExposeFunc. The action makes a Go function available as window.<name>, and a script of the page calls it like an async function that returns a promise. The program exposes four functions. The first gets an object and returns an object, with a lookup in a Go map. The second gets several arguments and returns a number. The third returns a Go error, so the promise rejects and the script catches it. The fourth is slow, and the page calls it five times at the same time. The program then navigates to a page with an iframe, and shows that the functions are still there, in the page and in the iframe. For each call it prints what the page got. It starts a local server and needs no internet. Use -v to print the protocol messages and -visible to show the browser window and leave it open. Use -visible-on-terminal to draw the page in the terminal with terminal graphics.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL