Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set anchor within an iframe inside of the dom. #1436

Closed
5 tasks done
SamHoque opened this issue Feb 15, 2025 · 2 comments
Closed
5 tasks done

Unable to set anchor within an iframe inside of the dom. #1436

SamHoque opened this issue Feb 15, 2025 · 2 comments
Labels
question A question about usage, not a bug

Comments

@SamHoque
Copy link

Describe the bug

If the element inside of the dom is located inside of an iframe, the anchor for content script does not work.

Reproduction

await createShadowRootUi(ctx, { anchor: 'iframe', ... });

Steps to reproduce

No response

System Info

npx envinfo --system --browsers --binaries --npmPackages wxt,vite

  System:
    OS: Windows 11 10.0.22631
    CPU: (24) x64 12th Gen Intel(R) Core(TM) i9-12900K
    Memory: 4.56 GB / 31.79 GB
  Binaries:
    Node: 18.20.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.2 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.2.2 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (124.0.2478.80)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    wxt: ^0.19.22 => 0.19.22

Used Package Manager

pnpm

Validations

@SamHoque SamHoque added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Feb 15, 2025
@aklinker1
Copy link
Collaborator

aklinker1 commented Feb 15, 2025

You need to inject your content script into all frames, so it runs inside the iframe as well as the parent window.

export default defineContentScript({
  allFrames: true,
  // ...
});

I forget if the script's matches needs to match the iframe's URL as well... I think it just needs to match the parent page's URL.

@aklinker1 aklinker1 added question A question about usage, not a bug and removed pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug labels Feb 15, 2025
@aklinker1
Copy link
Collaborator

aklinker1 commented Feb 15, 2025

Alternatively, if the iframe is from the same origin, you can use a function that returns an element instead of a query string for the anchor. Inside it, you can get the iframe's document and query elements inside the iframe.

createShadowRootUi({
  anchor: () => {
    // ...
  },
});

https://wxt.dev/api/reference/wxt/client/interfaces/ContentScriptAnchoredOptions.html#anchor

@aklinker1 aklinker1 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about usage, not a bug
Projects
None yet
Development

No branches or pull requests

2 participants