iframe cross origin problem

316 views
Skip to first unread message

Akash Kumar

unread,
May 30, 2024, 8:30:49 AM5/30/24
to Chromium Extensions
Hi m trying to target video element in a iframe but m getting error 

Blocked a frame with origin "https://www.targetwebsite.com" from accessing a cross-origin frame.
How can i target video inside iframe if i get this error


woxxom

unread,
May 30, 2024, 9:17:19 AM5/30/24
to Chromium Extensions, Akash Kumar

Akash Kumar

unread,
May 30, 2024, 11:02:05 PM5/30/24
to Chromium Extensions, woxxom, Akash Kumar
Thanks

woxxom

unread,
Jun 8, 2024, 7:06:03 AM6/8/24
to Keval Kankrecha, Chromium Extensions

I don't see your code, but judging by the error you're still trying to access the contents of iframe from outside, which won't work. The point of "all_frames": true is to have a separate instance of the content script running inside the iframe, so it can access its document directly.

On 08-Jun-24 13:57, Keval Kankrecha wrote:
in my case not working

  1. then: [Exception: DOMException: Blocked a frame with origin "https://www.secop.gov.co" from accessing a cross-origin frame.]

woxxom

unread,
Jun 8, 2024, 7:27:57 AM6/8/24
to Chromium Extensions, woxxom, Keval Kankrecha
1. There's a typo: all_frame should be all_frames.

2. Your code is still accessing the iframe from outside (iframe.contentWindow). You don't need it, remove this code. Your content script is already running inside the iframe. Both instances of your content script receive the message in the main page and in the iframe. You can tell the difference by checking (window === top)

On 08-Jun-24 14:20, Keval Kankrecha wrote:
> chrome.runtime.onMessage.addListener(async (message) => {
>   console.log({ message });
>
>   iframe = document.querySelector('#iframeEauction');
>   console.log(iframe.contentWindow)
>   //error here
>   switch (message.action) {
>     case "startBiddingNow":
>       if (isAuctionStarted) startBidding();
>       break;
>     case "deleteAndBid":
>       if (!storage.detectAndStartBiddingRunning) {
>         startDetectAndBidding();
>       }
>       break;
>   }
> });
>
> On Sat, Jun 8, 2024 at 4:50 PM Keval Kankrecha <kkj6...@gmail.com> wrote:
>
>>>                             Please check code
>
>      {
>       "name": "SECOP Auction Bidding",
>       "description": "SECOP Auction Bidding automation",
>       "version": "1.0.0",
>       "manifest_version": 3,
>       "content_scripts": [
>         {
>           "run_at": "document_start",
>           "matches": ["https://www.secop.gov.co/*"],
>           "js": ["src/content-script.js"],
>           "all_frame":true
>         }
>       ],
>       "action": {
>         "default_popup": "src/popup/index.html"
>       },
>       "host_permissions": [
>         "https://www.secop.gov.co/*"
>       ],
>       "permissions": ["storage", "tabs"]
>     }
>

woxxom

unread,
Jun 8, 2024, 7:37:39 AM6/8/24
to Keval Kankrecha, Chromium Extensions

Assuming you reloaded the extension in chrome://extensions page and reloaded the tab, the problem is in your other code and you'll have to debug it. Use devtools to set breakpoints and see what happens when the message arrives. Note that it will trigger more than one time because each instance of the content script receives a message. You can tell the difference by checking (window === top)

On 08-Jun-24 14:34, Keval Kankrecha wrote:
still problem is not solved provide me correct solution
Reply all
Reply to author
Forward
0 new messages