How to detect refresh of a webpage in chrome extension [duplicate]

In chrome extension – chrome.tabs does not have any direct event to be fired when a page is refreshed on a particular tab.
We do have an onUpdated event which passes all the changes as arguments in its callback that has taken place since the last update when fired.

Is there any way of detecting through changes in the onUpdated event or in any other event to precisely detect the event of the page getting refreshed in a particular tab

chrome extension message passsing: sendResponse is not a function

In my Chrome extension, I’m trying to exchange data between an internal web page of the extension chrome-extension://myExtensionId/path/to/web/page.html and content scripts.

So, in order to make this data persistent among different content scripts, I’m trying to save it as global variables in the extension’s background! I do so using message passing.

My problem is:

When I try to send a response back from the background I get this error:

Error in event handler for (unknown): TypeError: sendResponse is not a
function

I followed the documentation’s examples and this is my attempt:

In the scriptOfTheInternalPage.js :

var message = {
    'order': 'setData',
    'varName': 'myArray',
    'data': myArray
};
extPort.postMessage(message, function (response) {
    console.log('response:n', JSON.stringify(response));
});

In background.js :

var globals = {
    'myArray': [],
    ...
};
chrome.runtime.onConnect.addListener(function (port) {
    port.onMessage.addListener(
            function (message, sender, sendResponse) {
                console.log(
                        'the port received this message:n', JSON.stringify(message), 'n',
                        (sender.tab) ? ' from tab #' + sender.tab.id : ' from the extension!'
                        );
                if (message.order === 'setData') {
                    globals[message.varName] = message.data;
                    sendResponse({'response': 'data saved!'}); //<=====
                }
                return true; //<=== tried to return true here as well;
            });
});

Does this error means I should create a brand new function outside of the onMessage event listener?

I'm confused! What am I missing?

Does Topic messaging work with chrome extensions?

I am trying to implement Chrome Extension that receives push messages from Firebase.I have tried referring firebase docs but I cannot find any info regarding this.Is it possible to implement the same? Any reference document link is appreciated.

Delete all CSP headers with Chrome Extension to allow iframing

I’m trying to create a Chrome Extension that will inject an iframe sidebar onto any page. I ran into a problem with some sites using CSP directives to restrict what can be framed (example below is LinkedIn). What I thought I would try instead is use onBeforeSendHeaders to catch all the content-security-policy headers and delete them, but I’m not having any success.

Refused to frame ‘https://example.com/‘ because it violates the
following Content Security Policy directive: “frame-src ‘self’
*.doubleclick.net www.slideshare.net radar.cedexis.com platform.linkedin.com media-exp1.licdn.com media-exp2.licdn.com
m.c.exp1.licdn.com m.c.exp2.licdn.com media-lcdn.licdn.com
m.c.lcdn.licdn.com cdn.embedly.com https://www.linkedin.com
lichat.azurewebsites.net www.youtube.com www.facebook.com
player.vimeo.com embed.ted.com livestream.com embed.gettyimages.com
w.soundcloud.com www.lynda.com media.licdn.com”.

Here’s my manifest file:

{
    "manifest_version": 2,
    "name": "My Ext",
    "description": "My ext desc",
    "version": "0.1",
    "content_scripts": [{
        "matches": [""],
        "js": ["jquery-3.3.1.min.js","content.js","scripts.js"],
        "css": ["content.css"]
    }],
    "background": {
        "scripts": ["background.js"]
    },
    "permissions": ["tabs","activeTab","storage","webRequest","webRequestBlocking",""],
    "browser_action": {
        "default_icon": {
            "16": "images/icon16.png",
            "32": "images/icon32.png",
            "48": "images/icon48.png",
            "128": "images/icon128.png"
        }
    },
    "icons": {
        "16": "images/icon16.png",
        "32": "images/icon32.png",
        "48": "images/icon48.png",
        "128": "images/icon128.png"
    }
}

And here’s the code in my background.js trying to delete the headers:

chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
    console.log(details.requestHeaders);
  for (var i = 0; i < details.requestHeaders.length; ++i) {
    if (details.requestHeaders[i].name === 'content-security-policy') {
      details.requestHeaders.splice(i, 1);
      break;
    }
  }
  return {requestHeaders: details.requestHeaders};
},
{urls: [""]},
["blocking", "requestHeaders"]);

Any ideas where I’m going wrong?

Using global variables for updating Chrome extension’s popup UI continuously?

I want to be able to update a dashboard-like Chrome extension with long-running calculations and network activity happening in the background.
There’s plenty of answers about how to accomplish this and generally the answer is events.

However, when the popup.html is closed, its “state” is lost and when opened again it needs some kind of an initializer to update the UI again.

So this makes the chrome.runtime “bus” not ideal if you have events that don’t make their data known very often, which I do.

This leaves me with the option of creating a global variable like var STATS = {}, then polling from the popup via setInterval OR simply broadcasting STATS through the bus when it’s updated (which would requir lots of functions scattered all over the place). I’m still concerned about async functions accessing properties on that object simultaneously (potentially)

How do I continuously update the UI? Is it ok to use globals in this case? Where can I read some best practices?

How to block specific get and post requests?

I need to create a chrome extension in which I have to write a javascript code to block specific get and post requests based on checking the condition.
I want to know how do I do that.

Changing the url of updated tab updates it again. How can i get rid of this loop?

Code:

chrome.tabs.onUpdated.addListener( function(){
            chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) 
       {

    //...getting and changing the url...

    chrome.tabs.update(tabId, {url: newUrlString});


        }); });

I am trying to change the url of a tab (before it loads the page which doesnt get done by this code i guess). Code works but it works indefinitely since i am looking for the updated tabs and updating the same tab at the end of the function. What am i supposed to do here? Thanks

Chrome OS Notification Shelf Icon

How can I create a shelf icon for Chrome OS notifications? Using web notifications would be preferred, but using extension notifications is also acceptable.

Update: It seems that appIconMaskUrl of extension notifications adds an icon to the shelf, but the icon is an all white square.

This image demonstrates the desired behavior.

enter image description here

Can you overwrite CSP with Chrome Extension when injecting content?

I’m attempting to create a Chrome extension that injects a sidebar onto the page with an iframe inside, pointing at an external page. When testing, I ran into the following error on LinkedIn:

Refused to frame ‘https://example.com/‘ because it violates the
following Content Security Policy directive: “frame-src ‘self’
*.doubleclick.net www.slideshare.net radar.cedexis.com platform.linkedin.com media-exp1.licdn.com media-exp2.licdn.com
m.c.exp1.licdn.com m.c.exp2.licdn.com media-lcdn.licdn.com
m.c.lcdn.licdn.com cdn.embedly.com https://www.linkedin.com
lichat.azurewebsites.net www.youtube.com www.facebook.com
player.vimeo.com embed.ted.com livestream.com embed.gettyimages.com
w.soundcloud.com www.lynda.com media.licdn.com”.

I understand this to mean they’re blocking embedding any site other than those they’ve whitelisted, so I was curious if there’s any way to alter the CSP via the extension?

Here’s my manifest file:

{
    "manifest_version": 2,
    "name": "my ext",
    "description": "my ext desc",
    "version": "0.1",
    "content_scripts": [{
        "matches": [""],
        "js": ["jquery-3.3.1.min.js","content.js","scripts.js"],
        "css": ["content.css"]
    }],
    "background": {
        "scripts": ["background.js"]
    },
    "permissions": ["tabs","activeTab","storage"],
    "browser_action": {
        "default_icon": {
            "16": "images/icon16.png",
            "32": "images/icon32.png",
            "48": "images/icon48.png",
            "128": "images/icon128.png"
        }
    },
    "icons": {
        "16": "images/icon16.png",
        "32": "images/icon32.png",
        "48": "images/icon48.png",
        "128": "images/icon128.png"
    }
}

Closing chrome notification on MacOS triggers onClicked event

I have a Chrome Extension, which creates some notifications and listens for onClicked event on these notifications.

Everything works fine on Windows 10, but MacOS uses native notifications instead of Chrome ones, and when user clicks on notification’s close button, onClicked event is triggered, and there is no way to find out if user clicked notification’s content or close button in event listener…

Any workaround for this?