Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

247
Visualizações
Chrome/Firefox Extension: trying to create a popup over highlighted text but popup getting pushed off screen

Hi all,

So I'm making my first Firefox/Chrome extension (starting with Firefox bc go Firefox!) and I'm having trouble with the styling. Essentially, I want to be able to highlight a word, get a summary for it from wikipedia, and then display the summary in a little popup. I've got all that working, my problem is that unless I'm on a super basic site, my popup is getting pushed all over the place (usually to the bottom of the screen).

Here's some pics:

Working:

enter image description here

Not working:

enter image description here

My code: full source code

So I always have a variable for a card in my js. When I want to add the card I update the text from my Wikipedia API call and add it to the html and when I want to remove it I remove it from the HTML. Easy enough.

Previously I had problems with styles overriding my own styles, so I put my card in a shadow DOM. Basically, I create a placeholder div, append it to the document body, and attach a shadow dom to it. Then I just add my card into the shadow dom:

const shadowHost = document.createElement("div");
shadowHost.className = "wikiclick";
shadowHost.style.position = "absolute";
shadowHost.style.zindex = "2147483647";
document.body.insertBefore(shadowHost, document.body.firstChild);
let shadow = shadowHost.attachShadow({ mode: "open" });

When I highlight something, I get the x and y position of the highlight so I know where to position my card. I'm trying to use that and absolute positioning for my "shadowHost" div to render my card in the right place, but obviously it doesn't seem to work. Interestingly, on the working example, you can see that the x and y position get added to the inline styles, but in the non-working example they don't. I think it has to have something to do with the website overriding my styles/forcing itself onto my component.

Working:

enter image description here

Not working:

enter image description here

I am super thoroughly confused. Any advice for how to get my popup in the right place would be verrrrry much appreciated!!!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda