Trying to build a bookmarklet to capture the current page HTML, open a local validator file, and insert that markup into its textarea. Local file fails to load.
javascript:(function(){
let pageMarkup = document.documentElement.innerHTML;
let newWin = window.open('file:///C:/Validator/verify.html', '_blank');
newWin.onload = function(){
document.getElementById('verifyBox').value = pageMarkup;
};
})();
This approach often fails due to browser security settings that are applied when opening local files. After encountering similar issues, I learned that instead of directly loading a file via the file:// protocol, hosting the validator on a local server can resolve the problem. When using a local server, the validator page is served over HTTP, thus avoiding security restrictions that block JavaScript from manipulating elements in file pages. This simple change ensures that the onload event triggers correctly, allowing the HTML markup to be inserted into the textarea.