Reputation: 778
I have a chrome extension that can autofill form inputs. The issue I am facing is the iframe
is loaded from a different source. So, Chrome restricts the script that I inject into the page from accessing the iframe. There are lots of questions about this issue on SO already.
Recently I've found that the extension by privacy.com can insert an HTML element into the same iframe
without any issues. How is this being achieved?
To reproduce,
top
is set as the JS context in the console)document.querySelectorAll('iframe')[0].contentWindow.document.querySelector('#credit-card-number');
This will error with the following message
Uncaught DOMException: Blocked a frame with origin "https://codepen.io" from accessing a cross-origin frame.
at <anonymous>:1:53
The error is expected, which I also see when trying to do the same from my extension. So, what technique is Pay by Privacy.com using to make it work?
Upvotes: 1
Views: 944
Reputation: 51
Use all_frames option in chrome extension's manifest.json.
You script will run directly inside every iframe.
I emailed @Jahir, and he told me this answer. then wrote down here to help other people from wasting hours searching to get this simple answer.
Upvotes: 1