Set window.location.hash for local file?

44 views
Skip to first unread message

Hamish MacDonald

unread,
May 8, 2019, 8:35:01 AM5/8/19
to jsdom
Hello.
Just wondering if it is possible to load a local HTML file (with JS) and set its window.location.hash before the JS on the page is run?
"JSDOM.fromFile('../site/index.html#test', options)" does not open the file.
Cheers

Hamish MacDonald

unread,
May 8, 2019, 11:20:45 PM5/8/19
to jsdom
JSDOM.fromURL(`${fullpath}/index.html`, options).then((dom)
JSDOM.fromURL(`${fullpath}/index.html#test`, options).then((dom)
Both do not work due to: "TypeError: Invalid URL:"

JSDOM.fromFile(`${fullpath}/index.html`, options).then((dom)
Works but is not utilising location.hash.

JSDOM.fromFile(`${fullpath}/index.html#hash`, options).then((dom)
Does not work due to: "[Error: ENOENT: no such file or directory, open '/full/path/here/index.html#test']"

Hamish MacDonald

unread,
Jun 4, 2019, 8:48:59 PM6/4/19
to jsdom
Solved. Used GoogleChrome/puppeteer instead.
Reply all
Reply to author
Forward
0 new messages