Change Input type with javascript, everywhere it could be

I would like to change Input type with javascript, everywhere it could be, even in an eventual frameset / Iframe.

I want to use this method to see saved password in chrome directly in the page where **** are shown, without going into setting / password / search url / click sho / inser win credential / etc…

Until today I have used simply to open Chrome DevTool (F12) and modify on-fly the type of the input (from tpe=“password” to type=“text”)

Then I found a quick system: I saved a bookmark on chrome in which the url is set with the following:

    javascript:(function(){
    var ac,c,f,fa,fe,fea,x,y,z;
    ac="type";
    c=0;
    f=document.forms;
    for(x=0;x<f.length;x++){
        fa=f[x].attributes;
        for(y=0;y<fa.length;y++){
            if(fa[y].name.toLowerCase()==ac){
                fa[y].value="text";
                c++;
            }
        }
        fe=f[x].elements;
        for(y=0;y<fe.length;y++){
            fea=fe[y].attributes;
            for(z=0;z<fea.length;z++){
                if(fea[z].name.toLowerCase()==ac){
                    fea[z].value="text";
                    c++;
                }
            }
        }
    }
    alert("Modifica '"+ac+"' applicata su "+c+" oggetti.");
})();

This work perfectely, except when the page does not have a <form> (i found some) and when <input> are inside a frameset or iframe

Here is an example:

https://wificommunity.vodafone.it/

Login module is included in a iframe:

<iframe width="192" height="190" frameborder="0" src="/captiveportal/jsp/login_form.jsp" id="login"></iframe>

So i would like to have a little help to adapte the code to let it find ALL the input tags, also the one in a iframe or frameset.

Hi @info2765, you can access the iframes on the page via window.frames, which gives you a list of the corresponding window objects. Once the iframe has loaded the DOM, you can then access it as usual:

Array.from(window.frames).forEach(function (frame) {
  frame.addEventListener('DOMContentLoaded', function () {
    frame.document
      .querySelectorAll('[type="password"]')
      .forEach(function (input) {
        input.type = 'text'
      })
  })
})
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.