Skip to content

GM API Reference

PageMod implements standard Greasemonkey APIs (GM_*). User scripts declare required APIs in their @grant block to obtain the corresponding permissions. See the Tampermonkey documentation for the full API reference.

Grant-Required APIs

APIDescription
GM_setValue(key, value)Store key-value data (local, scoped per script)
GM_getValue(key, default?)Read stored data
GM_deleteValue(key)Delete stored data
GM_listValues()List all keys stored by this script
GM_xmlhttpRequest(details)Make cross-origin HTTP requests (bypasses CORS)
GM_cookie(action, details)Read/set/delete cookies (action: 'list'/'set'/'remove')
GM_setClipboard(text, type?)Write text to system clipboard
GM_notification(text, title?, image?, onclick?)Show desktop notification
GM_openInTab(url, options?)Open URL in a new tab
GM_download(url, name?)Download a file locally
GM_registerMenuCommand(name, fn, accessKey?)Register a right-click menu item
GM_addValueChangeListener(key, callback)Listen for value changes (cross-tab sync)

Zero-Permission APIs (always available)

APIDescription
GM_infoGet script metadata (name, version, namespace, etc.)
GM_addStyle(css)Inject CSS styles into the page
GM_addElement(parent, tag, attributes?)Create a DOM element (supports script/link/style, etc.)
GM_log(...messages)Log messages to the console
unsafeWindowAccess the page's original window object

Communication Mechanism

GM API calls are passed via performance CustomEvent between the MAIN world (user script) and ISOLATED world (content script), then forwarded from the content script to the Service Worker via chrome.runtime.sendMessage. This architecture ensures secure isolation between user scripts and extension code.