Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

412
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!