• Bookmarklet code works console, but not from bookmark. Is it caused by

    From Alfred@21:1/5 to All on Sun Jul 2 23:43:14 2023
    I am filling a form automatically with a bookmarklet, with lines of code like

    document.getElementById('id_but1').value = " a"

    The code works in the browser console, but not as a bookmarklet.

    From reading this SO answer I suspect the problem is caused by iframes.

    https://stackoverflow.com/questions/51723626/bookmarklets-doesnt-work-when-run-from-bookmark-but-works-from-console

    SO suggests a piece of code like

    let Iframe = document.getElementById('iframe_id').contentWindow.document
    let value = Iframe.getElementById("textboxID").value = "Some Text"

    The problem in my case is that I don't know the id for the iframe,
    i.e., I don't know 'iframe_id'.

    Any suggestion for knowing the ids of the iframes?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JJ@21:1/5 to Alfred on Mon Jul 3 17:48:07 2023
    On Sun, 02 Jul 2023 23:43:14 +0000, Alfred wrote:
    I am filling a form automatically with a bookmarklet, with lines of code like

    document.getElementById('id_but1').value = " a"

    The code works in the browser console, but not as a bookmarklet.

    From reading this SO answer I suspect the problem is caused by iframes.

    https://stackoverflow.com/questions/51723626/bookmarklets-doesnt-work-when-run-from-bookmark-but-works-from-console

    SO suggests a piece of code like

    let Iframe = document.getElementById('iframe_id').contentWindow.document
    let value = Iframe.getElementById("textboxID").value = "Some Text"

    The problem in my case is that I don't know the id for the iframe,
    i.e., I don't know 'iframe_id'.

    Any suggestion for knowing the ids of the iframes?

    If the IFRAME content is served in a different origin than the IFRAME host, it's not possible since bookmarklets are run in the main page context (the IFRAME host) due to XSS.

    A workaround is to use UserScript to run code in the IFRAME content's
    context, where the bookmarklet code sends a message event into the IFRAME content to notify the UserScript message event listener to run a code.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)