Skip to content

Run JavaScript before change detection

dgtlmoon edited this page Nov 6, 2022 · 31 revisions

You can run JavaScript before performing change detection and filters/triggers, this is handy for filling in fields, clicking buttons and other actions

Under Watch Settings > Request > Execute JavaScript before change detection

Available in 0.39.17

Requires Playwright driver enabled, or is included in the paid subscriptions

Examples:

Fill in the search box and click submit

At http://www.quotationspage.com/random.php ( shared watch import link https://changedetection.io/share/qvQ8NFFxQsMa )

document.querySelector("input[name=homesearch]").value="cause and effect";
document.querySelector("input[name=startsearch]").click();

Login to some portal with username and password

document.querySelector("input[name=username]").value="big-john";
document.querySelector("input[name=password]").value="secret";
document.querySelector("input[type=submit]").click();

Perform a Google Search

document.querySelector("input[type=text]").value="stripes on a tiger never fade";
document.querySelector("input[value='Google Search']").click();

Accept or Reject cookie/data

Basically just search for the <span> containing Reject all and click it

document.evaluate("//span[contains(., 'Reject all')]", document, null, XPathResult.ANY_TYPE, null ).iterateNext().click();

Accept cookie alert info

https://edition.cnn.com ( shared watch import link https://changedetection.io/share/-ANRwLTBCNMa )

document.getElementById('onetrust-accept-btn-handler').click();

Web page change alerts for BestBuy products

BestBuy will often ask for a 'local' or 'country' store, we simply click on the USA flag link from the English section of the site https://changedetection.io/share/pkhEFXeb8Cka

In that above shared link, we will be watching BestBuy for changes in GTX 4090 graphic card prices

Or set these

"Execute JavaScript before change detection" (If you get the country flag/location request)

setInterval(function(){
    document.evaluate("//div[@lang='en']//a[@class='us-link']", document, null, XPathResult.ANY_TYPE, null ).iterateNext().click();
},1000);

and "Wait seconds before extracting text" to around 5

"CSS/JSON/XPATH Filter" to .shop-sku-list-item (to just extract the product prices and price+description)

"Remove Elements" (optional, to cut down noise) to

.image-link
.embedded-badge
.variation-info
.sku-list-item-compare-checkbox
Clone this wiki locally