Execute JavaScript using "matches" without the need for the page to refresh

I have been developing a school project which involves creating a Chrome extension to streamline the Checkout process on a website. In my manifest.json file, I specified that a content.js file should run when it matches a specific URL.

"content_scripts": [
         {
            "matches": [
                "https://www.solebox.com/de_DE/checkout?stage=payment*"
            ],
            "js": ["payment.js"]
        },
        {
            "matches": [
                "https://www.solebox.com/de_DE/checkout?stage=placeOrder*"
            ],
            "js": ["placeorder.js"]

As you can see in the link, there are various stages during checkout. However, from the "payment" stage to the "place order" stage, the page does not refresh. This means that the script may not detect the change in URL and as a result, the JavaScript cannot be executed. Is there a way for the Chrome extension to continuously monitor the URL?

Answer №1

If you want to inject specific scripts based on the tab-url, consider utilizing the webNavigation API in Chrome extensions.

chrome.webNavigation.onBeforeNavigate.addListener(function (tab) {
  chrome.tabs.get(tab.tabId, function (results) {
        if (results.url.match("specific URL")) {
            chrome.tabs.executeScript(tabId, {
                file: "customScript.js" 
            });
        } 
    });
});

To learn more about the webNavigation API, check out the documentation here

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

Is there a way to apply the active class without relying on an anchor element?

After creating a one-page website, I utilized JavaScript to prevent the hash from appearing in the URL. Here is the HTML code: <ul class="click crsl"> <li><a class="page1 dot active"></a></li> <li><a class=" ...

A JavaScript function that smoothly scrolls an element into view while considering any scrollable or positioned parent elements

I needed a function that could smoothly scroll a specific element into view with some intelligent behavior: If the element is a descendant of a scrollable element, I wanted the ancestor to be scrolled instead of the body. If the element is within a posit ...

Issue with ReactiveVar causing React component not to re-render

I am a beginner with React in Meteor. To summarize: When I change the value of my ReactiveVar in my data container, the view does not update. Here is the code snippet: import React, { Component, PropTypes } from 'react'; import ReactDOM from & ...

Dynamic Checkbox Functionality in REACT

Motivation: My goal is to generate multiple rows with a variable number of checkboxes that will be managed by a useState hook. Challenge: The page freezes or displays constant loading, with no content visible. There are no console logs, and even the debug ...

Customize the behavior of jQuery cycle with an <a> tag

Can the jQuery cycle be accessed through a link in order to override the i variable? I've come across examples that can achieve this, but not in a scenario like this where the cycle() function is located within a variable: $(document).ready(function ...

Encountering a Next.js application error while utilizing the button tag in conjunction with generating metadata

I keep encountering an issue with generateMetaData when trying to utilize the button tag. Can you help me resolve this problem? Currently, I am working with nextjs and I am unable to properly use the <button> tag. Whenever I implement generateMetaD ...

Froala text area is unexpectedly visible when I attempt to cover it with a partially see-through mask

The website I'm currently developing features a semi-transparent overlay that dims the screen with a light-colored message displayed on top. This overlay and message are shown whenever there is a background process running. Everything was running smoo ...

Ways to inform a subelement that a task is complete?

I have a child component that displays a list of orders passed from the parent. I want to include a "Reload" button inside the child component that, when clicked, triggers a function in the parent component to reload the orders. Upon clicking the reload b ...

How do I navigate to the homepage in React?

I am facing an issue with my routes. When I try to access a specific URL like http://localhost:3000/examp1, I want to redirect back to the HomePage. However, whenever I type in something like http://localhost:3000/***, I reach the page but nothing is dis ...

What are some best practices for enhancing the elegance of this JS code?

Within my React app that utilizes Material UI components, I created a code snippet to handle the sizing of contact form fields. These fields are dynamic elements that can be added or removed based on certain configurations. Although the code I implemented ...

Converting a busboy file stream into a binary object in Node.js: A step-by-step guide

Seeking assistance with image file upload functionality by integrating Express and Node.js. Currently, I am utilizing the Busboy package to receive binary data in a file format. Specifically, my inquiry revolves around understanding how to capture this bi ...

What is the best way to retrieve promiseValue from the response array?

I've run into some challenges while using Promise.all() for the first time with two get-methods. When I check the response in my console log, I can see the data I'm trying to fetch under promiseValue. However, I'm unsure of how to access it. ...

Check to see if modifying the HTML using jQuery results in any errors

Although it may sound straightforward, let me clarify. I am utilizing ajax calls to update the content of the body and I aim to trigger an alert if the updating process fails on the client side, specifically after receiving a response from ajax in case of ...

Showing the ng-controller contents post executing AJAX request using the "as" method

My goal is to display the contents of ng-repeat after making an AJAX call using $http. <table ng-controller="TableController as tc"> <tr> <th>Date</th> <!-- other headers are here --> ...

Data not displaying in Vuetify table

Can someone help me with a table display issue in Vuetify? I've tried various solutions but my data is not showing up on the table, although I can see it using the dev tools. Here's a screenshot of how the data looks in the dev tool I've s ...

Passing a Javascript variable to the NAME attribute of an HTML <a href> tag: Steps to do it efficiently

I need assistance with passing a JavaScript variable to the NAME attribute of an HTML tag. Let's consider this script example: <script> var name = "Click here!"; </script> My goal is to pass the variable to some code in order for <a ...

Minimize data once more using various key criteria

In my current setup, I have created a view that counts reports for different cities. function (doc) { if(doc.type == "report") { emit(doc.city_name, null); } } Using the _count reduce function, I get the following values: {'key': &a ...

Authenticate with Google using the Javascript API without causing a pop-up to appear

Here is the code I'm using to allow users to log in with their Google account via the Javascript API. HTML <a id="gp_login" href="javascript:void(0)" onclick="javascript:googleAuth()">Login using Google</a> Javascript function gPOnLoad ...

Ways to insert additional panels prior to and after a selected panel

A button is provided in the report designer detail band that, when clicked, should add new panels immediately before and after the detail panel. $parentpanel = $this.parents(".designer-panel:first"); This code snippet is used to locate the parent panel u ...

What is the benefit of using an IIFE in this particular way when constructing a JavaScript library?

Many libraries I've seen use a similar style to define their structure. Upon further inspection, I've noticed that the first self-invoking function is often related to Require.js or AMD systems, with 'factory' as an argument. My curiosi ...