Path: csiph.com!news.swapon.de!news.mb-net.net!open-news-network.org!.POSTED.178.197.201.147!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: Obtaining the DOM tree for a *.htm file on a local disc? Supersedes: <12162747.O9o76ZdvQC@PointedEars.de> Date: Tue, 21 Feb 2023 22:15:54 +0100 Organization: PointedEars Software (PES) Lines: 41 Message-ID: <5657000.DvuYhMxLoT@PointedEars.de> References: <7cb3d7c8-74e8-49d2-ba7d-ab6df813f0c1n@googlegroups.com> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Info: gwaiyur.mb-net.net; posting-host="178.197.201.147"; logging-data="3974651"; mail-complaints-to="abuse@open-news-network.org" User-Agent: KNode/4.14.10 Cancel-Key: sha1:E1Jf4+V4d7obqNzGHTBNAAWNzC0= Cancel-Lock: sha1:QRBuKKGBY2B/fZLvCOxyEVtZ8Ko= X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Is there a readily-available function which can be called from JavaScript > running in a normal modern browser which, given as an argument the name > (relative to the current directory, or maybe absolute) of an HTML file, > will return a reference to the parsed DOM tree of the BODY of the HTML, > including the Links, Anchors, etc. arrays? Apparently they have even killed file:// to file:// HTTP requests in/by Chromium 108 :-( | Access to fetch at 'file:///…' from origin 'null' has been blocked by CORS | policy: Cross origin requests are only supported for protocol schemes: | http, data, isolated-app, chrome-extension, chrome, https, chrome- | untrusted. So AFAIK it is only possible now with a local Web server where the target file is also a resource accessible via HTTP: fetch(httpURI).then(response => { response.text().then(response2 => { var doc = (new DOMParser()).parseFromString(response2, 'text/html'); /* Example */ console.log(doc.images); }); }); (WFM.) DOMParser is available since the time of Firefox 1 (2006). If you do not have fetch(), you should write one using XMLHttpRequest. -- PointedEars | Twitter: @PointedEars2 Please do not cc me. /Bitte keine Kopien per E-Mail.