Create a vue-based browser extension that spans multiple pages

I've initiated my project using vite-plugin-web-extension

Starting with a blank project using

yarn create vite-plugin-web-extension
, I managed to successfully load the extension in my Chrome browser.

My goal is to include a login page and another page accessible only to logged-in users. Assuming I need to create a new popup - although, being a first-time creator of a browser extension, I could be mistaken here.

To start, I created a page at src/pages/Login.vue:

<template>
  <div>
    <div>
      Login
    </div>
  </div>
</template>

Next, I created src/login.ts:

import Popup from "./pages/Login.vue";
import { createApp } from "vue";

createApp(Popup).mount("body");

Then, I made src/login.html:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Refodev - Login</title>
</head>

<body></body>

<script type="module" src="./login.ts"></script>
</html>

In src/pages/Popup.vue, I added a link that should redirect to the Login.vue page when clicked:

<script lang="ts" setup>
  import browser from "webextension-polyfill";

  function onClickLogin(e: Event) {
    e.preventDefault();

    console.log(browser.action);
    browser.action.setPopup({ popup: 'login.html' })
  }
</script>

<template>
  <div>
    <a href="/login" @click.native="onClickLogin">
        login here
    </a>
  </div>
</template>

However, the user isn't redirected to the popup as expected. Am I going about this the right way? Should I consider setting up vue-router? If so, would the setup be similar to a regular project?

Many thanks for putting effort into creating this project.

EDIT

Below is the output generated when building the extension:

$ vite build --watch --mode development
vite v4.3.9 building for development...

watching for file changes...

build started...

Build Steps
  1. Building src/popup.html indvidually
  2. Building src/background.ts indvidually

Building src/popup.html (1/2)
vite v4.3.9 building for development...
✓ 15 modules transformed.
dist/src/popup.html   0.39 kB │ gzip:  0.27 kB
dist/popup.css        0.39 kB │ gzip:  0.25 kB
dist/src/popup.js    59.83 kB │ gzip: 23.07 kB
✓ built in 351ms

Building src/background.ts (2/2)
vite v4.3.9 building for development...

watching for file changes...

build started...
✓ 4 modules transformed.
dist/src/background.js  10.01 kB │ gzip: 2.98 kB
built in 60ms.

✓ All steps completed.

✓ 1 modules transformed.
dist/manifest.json  0.27 kB │ gzip: 0.18 kB
built in 1721ms.

Opening browser...
Done!

The issue arises where login.html doesn't get exported appropriately.

Answer â„–1

A great idea is to utilize Vue Router in your project. By implementing this, you can house your entire Vue application within popup.html and navigate based on authentication requirements.

Given that it's a chrome extension, the initial opening of the popup will direct to a single page such as index.html, but you have the flexibility to redirect within your Vue app according to extension storage or state.

To my knowledge, there isn't an option to conditionally load a distinct popup page based on state. Therefore, integrating Vue routing seems like the most suitable approach.

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

Using vue-i18n, the Nuxt.js framework dynamically changes the website's style in terms of direction and font when switching languages

I am looking to split the global.scss (/assets/global.scss) file into two separate files, one for 'fa' language and the other for 'en' language within the assets folder. //globalfa.scss html{ direction:rtl !important } body{ font-famil ...

Personalize the appearance of your stackLabels in Highcharts with dynamic customization options

I recently created a bar graph using Highcharts. You can check it out here: http://jsfiddle.net/v1rbz41q/3/ Here's the code snippet I used: chartw.yAxis [0] .options.stackLabels.formatter = function () {              return "werfdc";   ...

Remove data from Firebase that is older than two hours

I need to implement a solution to automatically delete data that is older than two hours. Currently, I am iterating through all the data on the client-side and deleting outdated entries. However, this approach triggers the db.on('value') function ...

Success in building with Vue CLI 3 even when encountering lint errors

After setting up a project with Vue CLI 3 rc3 and enabling lintOnSave, I noticed that the linting errors are showing up as warnings during the build process without causing it to fail. Is this the expected behavior? If so, how can I configure it to make ...

The concept of setting a value is not defined in JavaScript when compared to

Within my primary python script, the following code snippet is present. @app.route('/accounts/test/learn/medium') def medium(): word = random.choice(os.listdir("characters/")) return render_template('accounts/test/medium.html', word=w ...

Guide on verifying the status of a switch toggle using Selenium and C#

I am having trouble verifying the current state of a switch ('on' or 'off') using selenium. The toggle appears in the 'on' position when the webpage loads, but it affects filter results in a table when switched off. I am unabl ...

XState: linking together multiple promises seamlessly without needing intermediate states

After reading the Invoking Multiple Services section, it seems that despite being able to invoke multiple promises, they appear to be triggered without waiting for the previous one to complete in my own tests. // ... invoke: [ { id: 'service1' ...

Changing the text of a button using ngClass in Angular's toggle functionality

Is there a way to modify the text of a toggled button class in Angular using Bootstrap? Currently, I have this code to toggle the class: html <!-- toggle button --> <button type="button" class="btn btn-primary mt-3 ml-3" (click)="status=!status ...

Adding / Deleting a Row in a sequence of floated divs

I have a group of div elements arranged side by side with the float:left style as shown below: <div id="container"> <div id=0" style="float:left">> Stuff </div> <div id=1" style="float:left">> Stuff </div> < ...

Having trouble with $cordovaImagePicker in Ionic-Framework?

I am encountering difficulties with the Image Picker ngCordova plugin in my ionic app. Whenever I try to execute the getPictures() function on android (both on my device and emulator), the app crashes. The function works on IOS in the emulator but not on a ...

Using the JSON stream object to loop through jQuery with the .each() method

CODE SNIPPET var IMController = { listIM: function () { var params = getUrlVars($("#getIM").attr("href")); $.ajax({ url: "listIM", type: "POST", dataType: "json", data: $.extend(params, { ...

Updating the state of a Next.JS router component with React.JS: A step-by-step guide

I've implemented a toggleswitch in my app that changes its state based on the dynamic URL parameters. For instance, if the URL includes a parameter named followType set to following (e.g. https://www.example.com/home?followType=following), I want the ...

Is it possible to use just one <map> tag for multiple images in jQuery or JavaScript?

I have multiple images on my website <img usemap="#slideMap_branches" src="branches.png" width="890" height="270" alt="Slide 4"> <img usemap="#slideMap_order" src="order.png" width="890" height="270" alt="Slide 2"> <img usemap="#slideMap_c ...

"Adjusting the position of the Icon in the Material UI ItemList to make it closer

How can I bring this icon closer to the text? I'm not sure how to do it. When I enter developer mode, it shows me this. https://i.stack.imgur.com/WzhB1.png I am uncertain about what the purplish stuff indicates. My objective is to move the icon to t ...

Utilizing the $primary SCSS variable within Angular Material 2

Currently, I am utilizing angular-cli and following the theming guide to develop a personalized theme for an angular/material2 application. Within the scss file, the primary and accent colors are linked to the $primary and $accent scss variables respectiv ...

The issue of object being undefined during attribute binding in Vue Lifecycle

I'm encountering an issue with the vue lifecycle - while the global objects are defined and data is retrieved in the DOM using {{ family.plusOne }}. However, when used as an attribute like :checked="family.plusOne", expecting a true value, it turns o ...

Issue: { error: 'Unrecognized interaction', error code: 10062} in discord.js version 14

Every command runs perfectly fine except for /rank, which triggers the "Unknown interaction" error. This only happens when there are no issues with error handling, such as providing a valid user id and rank id. When there are problems, it works fine. I pr ...

Unable to Show the Contents of the Item - AngularJS

I'm in the process of developing an application that will showcase job details within a modal window based on the selected template. To achieve this, I've integrated ui.bootstrap and ui.router. However, I'm encountering difficulties in displ ...

What causes the data property to supersede the return false in a jQuery ajax call?

Below is a block of code that I am currently working with: $("#contact_container form, #contact_details form").live( "submit", function(event) { $.ajax({ type: this.method, url: this.action, data: this.s ...

Using AngularJS ng-model to select options in a dropdown menu with WebDriver

In the following code snippet, an AngularJS based dropdown menu is implemented: <select _ngcontent-c1="" class="form-control ng-pristine ng-valid ng-touched"> After opening the list, I attempted to select a variable from this list using the code be ...