Can someone help me discover how to activate autocomplete for Chrome types within my Typescript Vue component?

I am facing an issue with my vue-component which I intend to use as an extension-popup. The problem is that I am unable to access the chrome extension APIs from within the .vue file.

The structure of the component is as follows:

<template>
    <div> 
        <button @click="handleClick"> Hey and ho </button>
    </div>
</template>

<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
    props: {
        
    },
    methods: {
        handleClick() {
            // Here is an example of code that I would like to use, it works but vetur indicates that it doesn't exist
            chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
                chrome.tabs.executeScript(
                    tabs[0].id,
                    {code: 'document.body.style.backgroundColor = "red";'}
                );
            });
        }
    },
})
</script>

Although the button functions correctly when I build and run the extension, it becomes inconvenient to test every single change due to uncertainty about spelling errors.

I have already installed @types/chrome and they work well in other .ts files except within .vue files. Can anyone provide a solution to this problem?

Thank you!

Answer №1

I recently ran into the same issue while working with Vite, Vue3, and TypeScript.

The solution I found was to add @types/chrome as a devDependency and specify it under the types section of my tsconfig.json file:

"types": ["@types/chrome"],

After making this adjustment, I was able to successfully use it in the script section of my .vue files. 🎉

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an enum in TypeScript can be accomplished by using the enum

What transformations do enums undergo during runtime in the TypeScript environment? Fruit.ts enum Fruit {APPLE, ORANGE}; main.ts let basket = [Fruit.APPLE, Fruit.ORANGE]; console.log(basket); The resulting main.js file remains identical to the .ts ver ...

What is the best way to find TypeScript typings using a web browser?

It seems like this question should have a straightforward answer, but despite my efforts to find it on both DefinitelyTyped and other sources, I'm coming up empty-handed. Is there a way to locate TypeScript typings for libraries without having to rel ...

Managing URLs for single page applications and Django

I've developed a single-page Vue.js application that utilizes HTML5 History Mode for routing and is served with Django. The urls.py in Django looks like this: urlpatterns = [ url(r'^$', views.home), url(r'^admin/', admin. ...

Combining VueJS 2 with ASP.NET MVC 5

I am a beginner with VueJS and I need to create a single page application within ASP.NET MVC5. I found this tutorial very helpful -> TUTORIAL However, when I tried to test VueJS2 Routes by creating a .vue page, the browser did not recognize "Import". ...

Is it possible that the Npm 'Dev' script, using Watchify, Browserify, and vueify commands to compile the Vue component and launch the Express server, is experiencing

I found a helpful tutorial on using Vue components with Express at . One of the steps involves setting up an npm dev script to compile the Vue component with Browserify/vueify, start Watchify, and then launch the Express Server. Although every part of th ...

Issue encountered with Typescript and Request-Promise: Attempting to call a type that does not have a call signature available

I have a server endpoint where I want to handle the result of an asynchronous request or a promise rejection by using Promise.reject('error message'). However, when I include Promise.reject in the function instead of just returning the async requ ...

When attempting to import the image path from a JSON file, a ReferenceError occurs stating that the data variable is not

I'm currently attempting to iterate through image paths in a JSON file and display them in a browser using the "img" tag. While hardcoded values work perfectly fine, I encountered an issue when trying to switch to a variable as outlined in this post: ...

Angular 8: ISSUE TypeError: Unable to access the 'invalid' property of an undefined variable

Can someone please explain the meaning of this error message? I'm new to Angular and currently using Angular 8. This error is appearing on my console. ERROR TypeError: Cannot read property 'invalid' of undefined at Object.eval [as updat ...

"Sorry, but window.print function is not available in this environment

Whenever I try to execute something in jest, I keep encountering the same error message: console.error node_modules/jest-environment-jsdom/node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Not implemented: window.alert at module.expor ...

nuxt-i18n ignoring routes with no fallback

I have a Nuxt application with multiple languages implemented using nuxt-i18n and ignored routes. nuxt.config.js … seo: true, parsePages: false, strategy: 'prefix_except_default', pages: { 'cats': { en: '/cats', ...

Tips for triggering a function when the range slider is adjusted

I'm looking to trigger a function whenever a user changes a range slider in my Vue.js project, and I also need to pass the new value to that function. The code snippet below shows what I have so far. <div cla ...

Is there a way for me to view the output of my TypeScript code in an HTML document?

This is my HTML *all the code has been modified <div class="testCenter"> <h1>{{changed()}}</h1> </div> This is my .ts code I am unsure about the functionality of the changed() function import { Component, OnInit } f ...

Ways to conceal button for inactive edit row on a table

I am trying to implement inline editing for a table in my application. The requirement is to hide the "Edit" and "Delete" buttons for all other rows when the user clicks on the edit button of a particular row. I have attempted to achieve this using the c ...

Utilizing UseRef in Typescript for an Idle Timer

Feeling frustrated with Typescript, everything seems unnecessarily complicated. Trying to follow a tutorial on react-idle-timer and encountering TypeScript compilation issues within minutes. The guides online suggest using when calling useRef with TypeS ...

Error message in Vue.js 3 stating that access to 'this' is

Vue.js 3 is new to me, and I've encountered a peculiar issue when trying to access the "this" object in a component. When I declare my component using the script setup, I always get undefined when trying to access the "this" object, as seen in the co ...

Is it necessary for me to develop an Angular library in order to release a basic TypeScript class that makes use of Angular components?

In one of my Angular projects, I have a Typescript class called APIResponse that I want to convert into an NPM package for use in other projects. This class is not specific to Angular like a Service or Component. After doing some research on creating non-A ...

How can Material UI React handle long strings in menu text wrapping for both mobile and desktop devices?

Is there a way to ensure that long strings in an MUI Select component do not exceed the width and get cut off on mobile devices? How can I add a text-wrap or similar feature? Desktop: https://i.sstatic.net/lo8zM.png Mobile: https://i.sstatic.net/8xoW6. ...

Inertiajs - Seamlessly transition to a different page within the same environment

Is there a way to navigate between pages on the client side in Laravel and InertiaJS without using inertia.visit()? I am curious about how to switch pages solely within the client, without having to communicate with the server. Can props be specified fro ...

Passing props using Vue's router-link feature with dynamic routing

I currently have the following route configuration: routes/index.ts { path: "/flower/:id", name: "SingleFlower", component: () => import("@/components/SingleFlower/SingleFlower.vue"), meta: { requiresAuth: true }, ...

Tips for avoiding the default rendering of Nuxt 3 layout?

After reviewing the Nuxt 3 documentation and finding it lacking in explanation, I turned to the Nuxt 2 docs. According to them, the default layout should be replaced by a specific layout specified within the name property of the <nuxt-layout> compone ...