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

415
Visualizações
Injecting script with chrome.scripting in TypeScript

I am trying to make chrome extension js code work with typescript:

    const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
    let result;
    try {
        [{ result }] = await chrome.scripting.executeScript({
            target: { tabId: tab.id },
            function: () => getSelection().toString(),
        });
    } catch (e) {
        return;
    }
    console.log('Selection: ' + result);
};

This logs user's selection on click of a button. However, when trying to work with this in typescript, it throws a cascade of errors at me. The first one is Property 'result' does not exist on type Property 'result' does not exist on type 'InjectionResult<unknown> | undefined'.

I have tried fiddling around with ! and ? operators, sending executeScript to a different function via func: but have not been able to get this to a working state. I also tried to make result and ordinary variable, but in this case No overload matches this call. exception is thrown on line 6. How do I go about resolving this? Also, can I find type reference for InjectionResult anywhere?

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