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

chrome.scripting.executeScript: func with args throws error #54

Open
D3strukt0r opened this issue Jul 24, 2023 · 2 comments
Open

chrome.scripting.executeScript: func with args throws error #54

D3strukt0r opened this issue Jul 24, 2023 · 2 comments

Comments

@D3strukt0r
Copy link

I tried to execute

await chrome.scripting.executeScript({
  target: {tabId: tab.id},
  func: (text) => {
    (document.activeElement! as HTMLInputElement).value += (text || '');
  },
  args: [text],
});

and TypeScript tells me

TS2769: No overload matches this call.
   Overload 1 of 2, '(injection: ScriptInjection): Promise<InjectionResult[]>', gave the following error.
     Type '(text: any) => void' is not assignable to type '() => void'.
       Target signature provides too few arguments. Expected 1 or more, but got 0.
   Overload 2 of 2, '(injection: ScriptInjection, callback?: ((results: InjectionResult[]) => void) | undefined): void', gave the following error.
     Type '(text: any) => void' is not assignable to type '() => void'.

as well as

TS7006: Parameter 'text' implicitly has an 'any' type.

the type definition looks a bit too simple compared to @types/chrome

    export interface ScriptInjection {
      func?: () => void;
      args?: any[];
      ...
    }
    export type ScriptInjection<Args extends any[], Result> = {
        target: InjectionTarget;
        world?: ExecutionWorld;
        injectImmediately?: boolean;
    } & ({
        files: string[];
    } | ({
        func: () => Result;
    } | {
        func: (...args: Args) => Result;
        args: Args;
    }))

Following might also be a separate issue, but maybe add to the docs that one has to add /// <reference types="chrome-types" /> to a .d.tssince at least for me, it didn't take it automatically.

@TheKonka
Copy link

TheKonka commented Nov 8, 2023

I meet the same problem.

@aoladuti1
Copy link

yup. still not fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants