How to trigger onDownloadProgress while installing Chrome Extension? - google-chrome-extension

I would like to know how to trigger the onDownloadProgress event. I made an extension, uploaded it to the Chrome Store and followed every step detailed here: http://developer.chrome.com/webstore/inline_installation
Now I'm trying to display a progress bar to users when they install my extension but I get the following error:
Uncaught TypeError: Cannot call method 'addListener' of undefined
this is the code I'm using:
chrome.webstore.onDownloadProgress.addListener(function(percentage){
console.log(percentage)
});
chrome.webstore.install('MY_EXTENSION_ID', function(){ console.log('installed') }, function(error){ console.log(error) });
It is part of their docs here: http://developer.chrome.com/extensions/webstore
and it's not working at all.

It looks like these events were added to Chrome's trunk code only 5 days ago. They are available now on Chrome Canary, but it will be a while until they are present in the regular Chrome channel.
I don't know why the documentation page is already listing them.

Related

How to show users information about extension updates, redirect to a url after update or other methods

In the past, I've seen other extensions be able to redirect you to an info page after the update is completed. I will soon be releasing an update and would like to inform users as soon as the update is completed. Not after they click the icon.
I came across update_info_url which can be placed in the manifest.json however it is unclear if it has been depreciated or not
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Updates#Update_objects
All other google results date back to 2009.
I'm just trying to figure out how to go about this, i believe I definitely have seen other extensions achieve this.
You can use something like this in the background script:
chrome.runtime.onInstalled.addListener(details => {
if (details.reason == 'update'){
chrome.tabs.create({url:'https://example.com/extensionupdated.html'});
}
});

How to fix 'Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.'

I have the following error in the Chrome Dev Tools console on every page-load of my Node/Express/React application:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
This error makes a reference to localhost/:1. When I hover over this, it shows http://localhost:3000/, the address I'm viewing the app at in the browser.
Anyone have an idea what is going on? Most of the other threads I've found that bring up this error seem to be related to someone trying to develop a Chrome Extension, and even then they tend to have very few responses.
I'd been getting the exact same error (except my app has no back-end and React front-end), and I discovered that it wasn't coming from my app, it was actually coming from the "Video Speed Controller" Chrome extension. If you aren't using that extension, try disabling all of your extensions and then turning them back on one-by-one?
I found the same problem when developing the Chrome extensions. I finally found the key problem.
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
The key problem is that when background.js sends a message to the active tab via chrome.tabs.sendMessage, the content.js on the page is not ready or not reloaded. When debugging. We must ensure that content.js is active. And it cannot be a page without refreshing , The old pages don not update you js itself
Here is my code:
//background.js
chrome.tabs.query({active: true, currentWindow: true},function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response);
});
});
//content.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
console.log(request, sender, sendResponse);
sendResponse('我收到你的消息了:'+JSON.stringify("request"));
});
The error is often caused by a chrome extension.
Try disabling all your extensions, the problem should disapear.
Solution
For Chrome:
You have the window open with the console error, open up a second new window.
In the second window, go to:
chrome://extensions
Disable each extension by toggling (the blue slider on the bottom right of each card), and refresh the window with the console after toggling each extension.
Once you don't have the error, remove the extension.
If you are an extension developer see this Chrome Extension message passing: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
The core of the problem is that chrome API behavior change and you need add a workaround for it.
You need to handle window.chrome.runtime.lastError in the runtime.sendMessage callback. This error just needs to be handled. Below is my code:
window.chrome.runtime.sendMessage(
EXTENSION_ID,
{ message:"---" }, // jsonable message
(result) => {
if (!window.chrome.runtime.lastError) {
// message processing code goes here
} else {
// error handling code goes here
}
}
);
});
🙂simple answer:🙂
if you have no response from another End it will also tell you Receiving end does not exist.
detailed answer:
if you have no answer from another end it will also tell you Receiving end does not exist. so if you have any callBack function which should use response in your .sendMessage part, you should either delete it or handle it if you probably have no response from another side.
so
if i wanted to re-write Simple one-time requests section of Message passing documents of google API i will write it with error handlers for callback functions in message-sending methods like this:
Sending a request from a content script looks like this:
chrome.runtime.sendMessage({greeting: "hello"}, function (response) {
if (!chrome.runtime.lastError) {
// if you have any response
} else {
// if you don't have any response it's ok but you should actually handle
// it and we are doing this when we are examining chrome.runtime.lastError
}
});
Sending a request from the extension to a content script looks very similar, except that you need to specify which tab to send it to. This example demonstrates sending a message to the content script in the selected tab.
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
if (!chrome.runtime.lastError) {
// if you have any response
} else {
// if you don't have any response it's ok but you should actually handle
// it and we are doing this when we are examining chrome.runtime.lastError
}
});
});
On the receiving end, you need to set up an runtime.onMessage event listener to handle the message. This looks the same from a content script or extension page.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting === "hello")
sendResponse({farewell: "goodbye"});
}
);
Removing 'Udacity Frontend Feedback' chrome extension solved the issue for me.
This was happening in Chrome for me and I discovered it was McAfee WebAdvisor. Once I disabled it, the message went away:
The simple fix is to return true; from within the function that handles chrome.tabs.sendMessage.
It's stated
here.
(this is similar to other answers)
I removed "Video Speed Controller" Chrome Extension and the error was removed.
It worked for me like this. In your case there may be some other extensions too which may cause this error.
It was tab bnundler for me: https://chrome.google.com/webstore/detail/tab-bundler/ooajenhhhbdbcolenhmmkgmkcocfdahd
Disabling the extension fixed the issue.
It was a few extensions for me. Disabling and then re-enabling fixed the problem though. Grammarly was one of them. Hope the errors don't return.
Oddly enough, for myself I simply disabled all my extensions and the error went away.
However, after re-enabling all of the ones I disabled, the error was still gone.
I was testing my extension on edge://extensions/ page/tab. Testing it on another tab solved this issue. I think this may also occur for chrome://extensions/.
This is caused simply by installed chrome extensions, so fix this first disable all chrome extensions then start to enable one after another to detect which extension is cause you can enable the remaining.
in my case removing 'adblocker youtube' extension work for me
For me the error was due to the onelogin chrome extension. Removing it fixed the issue.
Cacher Extension in my case - but yeah disable each and then reload page
This is usually caused by an extension.
If you don't want to disable or remove the extension which causes this error, you can filter out this specific error by typing -/^Unchecked\sruntime\.lastError\:\sCould\snot\sestablish\sconnection\.\sReceiving\send\sdoes\snot\sexist\.$/ in the Filter box in the console:
As far as I've seen, this filter will stay until you remove it manually, you can close and reopen the console, restart Chrome, etc as much as you want and the filter will never be removed automatically.
I get the message only on the first Chrome page =
When Chrome is not running, and I open it - either directly or by double-clicking on a page on my desktop.
(I don't know if this matters, but I have "Continue running background apps when Google Chrome is closed" off.)
So, I'm assuming it's Chrome's crap spying/"enhancing user experience" attempt.
I don't know what it's trying to send, but I'm glad it's not able to! :)
So, second (or any but first) tab has no error.
== No need to disable anything (extensions, etc.).
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
I "achieved" this error after
installing the Debugger for Chrome extension in Visual Studio Code,
debugging my code, and
closing and reopening the non-debugging Chrome window. (I had left Chrome running my app while debugging.)
Solutions:
Stop using the extension.
Refresh the non-debugging Chrome window.
Use a different debugger.
Of course, the console error reappears when I redo steps 2 and 3 above with the Debugger for Chrome. This encourages me to use other debuggers instead. Then I don't mistakenly think my own code produced the console errors!
For me this was caused by :
Iobit Surfing Protection & Ads Removal extension
which comes with Iobit advanced system care software. However, the console might provide you with relevant information on what you need do disable or the cause for that problem.
The likely cause of this error, as per google searches is because that extension which causes the error, might be using the chrome.runtime.sendMessage() and then tries to use the response callback.
Error shown in the console
Hope this information helps. Have a great day!
For chrome extension development, it's an error thrown by chrome.tabs.sendMessage method.
Here is the link of related documentation: https://developer.chrome.com/docs/extensions/reference/tabs/#method-sendMessage. In the link you can find the description for the callback function: If an error occurs while connecting to the specified tab, the callback is called with no arguments and runtime.lastError is set to the error message.
According to documentation above, the error is because of the specified tab. I restart chrome and reloaded the extension, and this issue is fixed
I solved this in following way. This is mainly chrome extension problem, try to first empty cache and hard reload for this inspect any window and hold reload button about 2 second then it will appear 3 options click last one which is mentioned above then go to manage extensions and turn off one by one and then turn on again one by one and check it's gone or not.
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist
chrome.runtime.lastError
It's an error that appear in the Chrome devTools console.
And it's related to Chrome Chrome Message Passing
Because of the 'rigid structure' of the Chrome platform, it's not easy to pass data between different Chrome windows/tabs, as it's common to do in the 'object oriented' programming languages.
In Chrome extensions, usually, there is not a single file of code, that runs for all pages or tabs.
It's a common use, to build many different files of code in javascript, for different Windows/tabs/url address.
So, when the software, need to pass data from different windows/tabs/url, it's made using 'message passing'
The 'message passing', allow to send a 'message' and wait to receive a message as 'callBack'
But sometimes happens, in example, that the url of a window, or a tab, change, when there is a 'message passing' function which has been triggered, but still not returned.
If this situation it's not managed by code (as wrote TechDogLover OR kiaNasirzadeh), or it's an old extension not updated, this error can arise.
So as others users said, it could be an extension, which is running in your Chrome.
But if your window doesn't crash, it doesn't have much sense disable an extension because of such message appear in the devTools Console.
And it doesn't have sense try to understand how to fix it (if you are not the developer of the software which is causing the error), because the variables are so many, that it's not said that the error will be triggered again, in the same situation.
In those cases, in my opinion, if you really want to do something, a good thing to do could be, once you find the extension that cause the error, contact the extension developer and report it.
And if you are the developer, you could check for a missing
if(!chrome.runtime.lastError){
// here if there is no error
} else {
// here if there is an error
}
Or, also you could check your code, if you did more than one callBack, e.g. as explained there
wOxxOm comment
I also encountered this problem when I was developing chrome extensions.
Error: Could not establish connection. Receiving end does not exist.
The error message from chrome.tabs.sendMessage
The solution is to make it return the promise and use catch to handle the error and define it yourself. Example
Apparently an error occurred during browser startup and the browser did not launch extensions such as stylish, adblock. I closed the browser and reopened it and my page worked without errors.

After deletion of chrome extension remove some html elements from website

Hi I am new to chrome extension. I have build the basic chrome extension and I want to install it using inline installation. I followed the following link :
https://developer.chrome.com/webstore/inline_installation#already-installed
All is working properly. I want to check if extension is already installed or not so I referred the above document, whenever user install the extension at that time we are appending the new div using content script to my installation page on website. If that div is present it means the extension is already installed.
Following code is added in my content_script of chrome extension for appending the div whenever the extension is installed:
var isInstalledNode = document.createElement('div');
isInstalledNode.id = 'extension-is-installed';
document.body.appendChild(isInstalledNode);
Then my installation page can check for the presence of that DOM node, which signals that the extension is already installed:
if (document.getElementById('extension-is-installed')) {
document.getElementById('install-button').style.display = 'none';
}
But I am facing one problem, whenever I deleted my extension from settings/extensions, still the div is present on extension's installation page.
Is their any provision to remove the div when my extension is deleted or removed from browser?
You can't catch the uninstallation event for your own extension, though there is an management.onUninstalled, it is used for listening to other extensions/apps. See following answer for more details:
How to listen to uninstallation event in javascript from a chrome extension?
I just come up with two workarounds, one is creating another extension to listen to the uninstall of your first extension; another one is using runtime.setUninstallURL to visit a URL upon uninstallation, you can do something in server if you want.
BTW, for isInstalledNode, you needn't/shouldn't set the id, since there may be other elements in the webpage with the same id, you just need to create the node and use document.body.contains(isIntalledNode) to check if it exists.

How to know if a page loaded via iframe is within sandbox? [duplicate]

This question already has answers here:
Detect if JavaScript is Executing In a Sandboxed Iframe?
(2 answers)
Closed 7 years ago.
I'm trying to detect if a page is loaded via a sandboxed iframe. Is this possible?
For example,we provide custom embeddable widgets and some people think they are being smart by sandboxing them in their iframe, but this breaks certain things.. such as window.top.location
Obviously, they could enable the features we need, but ideally, I should be able to just do something like:
"sandbox" in window.top
I have also tried doing
try {
// do something that would not work if within sandbox
} catch(e) {
}
But this doesn't work because it's a browser security error, and not related to javascript.
JSFiddle actually sandbox their iframes to prevent window.top.location navigation, so this would be a good example to show you.
If you look at this example here:
http://jsfiddle.net/mwsb8geL/show/
You can see the error when you press the Instant Book Online button.
A project sandblaster can help you detect if you running being sandboxed.
Inside the iframe where you are testing if it is sandbox, open up your script tag and paste the contents of https://raw.githubusercontent.com/JamesMGreene/sandblaster/master/dist/sandblaster.js. This is due to the security issue.
After this, its as simple as the following.
var result = sandblaster.detect();
if(result.sandboxed === true) {
//sandboxed
}
Here is a demo I made for another answer but shows that the solution works.

Google Wallet DOM Exception 18

Google Wallet seems to get stuck at the loading screen and doesn't show the form
google.load('payments', '1.0', {
packages: ['sandbox_config'],
callback: cbk})
Callback is
goog.payments.inapp.buy({
jwt: getToken,
success: function() {
console.log("success");
},
failure: function() {
console.log("fail");
}
});
Console shows
Uncaught Error: SecurityError: DOM Exception 18 5F00.cache.js:23
com_google_checkout_inapp_client_gwt_init_init
This is on Google Chrome - Version 25.0.1337.0 dev. It works for me on the demo page, but not on my own pages.
EDIT:
Installed Google Chrome Canary - Version 25.0.1347.2 canary
Seems to not be an issue, works perfectly in Canary - is this just a Google Chrome dev glitch or has anyone else seen this?
EDIT 2:
Now it doesn't work in canary either (1348) I have also tested in Chrome stable, where it works.
Actually it doesn't seem to be related to the browser version, as reinstalling Canary and wiping Application Support data files makes it work again
Is there a way to get support via email from Google somehow? I know it's Google and they don't talk to people, but maybe there is some way?
Based off of your experiences it seems like a Chrome dev glitch.
Sidenote: I'm not sure if testing your app in dev/canary releases is the best way to catch potential bugs. Are you also testing in IE/FF/Chrome stable?

Resources