when firefox extension is active, following SDK script sends me active status of the extension. here is the script...
worker.port.on("getAddonStatus", function( data ) {
var addonStatus = [];
AddonManager.getAddonByID( "jid1-Ek4rsiwaZyfJnw#jetpack" , function(addons){
//alert('addon script');
if ( !addons ) {
addonStatus.push({
status : 'failure',
id: '',
appDisabled: '',
});
} else {
addonStatus.push({
status : 'success',
id: addons.id,
appDisabled: addons.appDisabled,
});
}
worker.port.emit( "addonStatus", addonStatus );
});
});
why is not send me any response when firefox extension is disabled? please help me...
When your restartless/jetpack add-on is not enabled, it is not running either, simple as that. I.e your code that would perform the AddonManager.getAddonByID call is not running either.
Related
I am trying to deploy django web app on google cloud. I have tested on local machine and it appears to be working fine. But after I test it on google cloud port 80, the javascripts don't work.
Here is the django form where I am referencing the javascript function
class ScqQuestionForm(forms.ModelForm):
class Meta:
model = Single_ans_q
fields=['question_text']
widgets = {
'question_text' : forms.Textarea(attrs={
'placeholder' : 'Question',
'cols' : 140,
'rows' : 6,
'name':'questioninput',
'id': 'questioninput' ,
'onkeyup':'func_output()',
'required': 'True',
})
}
My javascript is
window.func_output = function () {
button.disabled = true;
output.innerHTML = input.value.trim();
MathJax.texReset();
MathJax.typesetClear();
MathJax.typesetPromise([output]).catch(function (err) {
output.innerHTML = '';
output.appendChild(document.createTextNode(err.message));
console.error(err);
}).then(function () {
button.disabled = false;
});
}
I get this error in the console
console error for javascript.
Further, in the console, I see my function
function in error console
The error only occurs on google cloud deployment, on local machines its running smoothly.
Have you check if you open port 80?
I'm developing web push notification on my website. I follow the Web Push Notifications of Google and The Service Worker Cookbook of Mozilla.
I have tested on the Google Chrome v50+ and everything is working but I will get the error below on Firefox 44, 45, 46, 52, latest Firefox (version 57.0.4 64 bit) when calling navigator.serviceWorker.register('./push-service-worker.js') function.
TypeError: ServiceWorker script at http://localhost:9600/push-service-worker.js for scope http://localhost:9600/ encountered an error during installation.
This is my code:
Register ServiceWorker in controller.js
navigator.serviceWorker.register('push-service-worker.js')
.then((registration) => {
return registration.pushManager.getSubscription()
.then((subscription) => {
if (subscription) {
return subscription;
}
var subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: buildApplicationServerKey(),
};
return registration.pushManager.subscribe(subscribeOptions);
});
})
.then((subscription) => {
sendSubscriptionToServer(subscription);
})
.catch((err) => {
console.log('Unable to subscribe to push: ', err);
});
push-service-worker.js
'use strict';
self.addEventListener('push', (event) => {
var payload = event.data.json();
var title = payload.title || 'Title';
event.waitUntil(
self.registration.showNotification(title, {
body: payload.body,
icon: './common/images/notification-icon-192x192.png',
image: payload.image || '',
})
);
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
var urlToOpen = new URL('/', self.location.origin).href;
event.waitUntil(
clients.matchAll({
type: 'window',
includeUncontrolled: true,
})
.then((windowClients) => {
var matchingClient = null;
for (var i = 0; i < windowClients.length; i++) {
var windowClient = windowClients[i];
if (windowClient.url === urlToOpen) {
matchingClient = windowClient;
break;
}
}
if (matchingClient) {
return matchingClient.focus();
} else {
return clients.openWindow(urlToOpen);
}
})
);
});
Directory structure
./root
---- manifest.json
---- push-service-worker.js
---- src
---- controller.js
Thank for helping!
As wanderview said at here:
FWIW, you should always use a separate profile for each channel (release/beta/dev-edition/nightly). We're working on making it work like that out-of-the-box, but its not ready yet.
This problem is encountered when I use one profile for multiple Firefox version. To fix this issue go to about:support and click Refresh Firefox. If it doesn't work, you can go to about:profiles, click Create new profile, and then Launch profile in new browser.
In my case, this was caused by Firefox not being able to access the serviceworker.js file.
The server I was hosting it on had a permissions check based on cookies, and in this case Firefox was not sending the cookie as I believe it was considered a cross-site script.
On the server, I made the serviceworker.js file accessible publicly, and then Firefox could register the service worker.
It was particularly difficult to notice this, because the Firefox Developer Tools did not show the Forbidden response in the Console, nor did it even show any request for serviceworker.js in the Network tab.
Therefore, presumably the TypeError is in fact a generic error and should be read as 'something went wrong registering the Service Worker'.
I've got a small angulaerjs app that uses angularjs resource in one of it's controllers. Here is the code for resource usage
$scope.getFilteredTasks = function (filter) {
var resource = $resource('{0}/api/orderTasks/filterTasks'.format($scope.baseUrl), { status: '#status', type: '#type', createdDate: '#createdDate', agentType: '#agentType', page: '#page', pageSize: '#pageSize' }, {
'response': { method: 'GET', isArray: false }
});
$('#loading').show();
resource.response({
status: filter.status,
type: filter.type,
createdDate: filter.createdDate,
agentType: filter.agentType,
page: $scope.currentPage,
pageSize: $scope.pageSize
},
function (result) {
$scope.resultTasks = result.Items;
if ($scope.totalItems != result.TotalCount)
$scope.totalItems = result.TotalCount;
$('#loading').hide();
},
function (result) {
$('#loading').hide();
alert('Error in request!')
});
};
When the page first load everything is fine and i get all data that i need. But when I make second request (for example push the button on page that calls getFilteredTask(filter) function). I've got an result.status = -1. According to Fiddler and Chrome Network tab in dev tools request has status 200 but was cancelled. I've also checked the backend and found no problems, request was succsessfully handled and server returned all data that I need but I get cannceled request on client side.
UPDATE
It loooks like this problem appears only in Chrome. In IE 11 for example everything is ok
the issue might be that you were making the ajax request from a link, and not preventing the link from being followed. So if you are doing this in an onclick attribute, make sure to return false; as well.
im trying to implement a facebook share function with a callback.
I have found this example script
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
<script>
function fb_share() {
FB.ui( {
method: 'feed',
name: "Facebook API: Tracking Shares using the JavaScript SDK",
link: "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
picture: "https://stackexchange.com/users/flair/557969.png",
caption: "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK."
}, function( response ) {
if ( response !== null && typeof response.post_id !== 'undefined' ) {
console.log( response );
// ajax call to save response
$.post( 'http://www.example.com/', { 'meta': response }, function( result ) {
console.log( result );
}, 'json' );
}
} );
}
$(document).ready(function(){
$('.share-btn').on( 'click', fb_share );
});
</script>
</head>
<body>
<button class='share-btn'>click</button>
</body>
</html>
However it doesn't seem to work, although some people say it works for them. When I click the button nothing happens. Is there an error somewhere? Or maybe someone could direct me to another sample. Would be very grateful!! Cheers.
It seems like you are missing a few things. I took a quick look at the Facebook JS SDK docs here, and it seems like you're missing a source for the SDK and an FB init method with your app credentials. For example:
function fb_share() {
FB.init({
appId : '{your-app-id}',
xfbml : true,
version : 'v2.0'
});
FB.ui( {
method: 'feed',
name: "Facebook API: Tracking Shares using the JavaScript SDK",
link: "https://www.webniraj.com/2013/05/11/facebook-api-tracking-shares-using-the-javascript-sdk/",
picture: "https://stackexchange.com/users/flair/557969.png",
caption: "Tracking Facebook Shares on your website or application is a useful way of seeing how popular your articles are with your readers. In order to tracking Shares, you must used the Facebook JavaScript SDK."
}, function( response ) {
if ( response !== null && typeof response.post_id !== 'undefined' ) {
console.log( response );
// ajax call to save response
$.post( 'http://www.example.com/', { 'meta': response }, function( result ) {
console.log( result );
}, 'json' );
}
});
}
Here is a JSFiddle with all that included http://jsfiddle.net/bn7F7/.
Hope that helps!
I am developing an extension in google chrome.I want to show desktop notification when any new page loads in currently active tab.
But my written code is not working properly.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
if (changeInfo.status === 'complete') {
chrome.tabs.executeScript(tabId, {
chrome.notifications.create(‘id1’, {
type: ‘basic’,
iconUrl: ‘icon.png’,
title: ‘Review Baed Surfing’,
message: ‘Check URL now by clicking FAKE URL icon infront on Address Bar!’,
priority: 0
},
function() { /* Error checking goes here */}
);
});
}
});
I think you only need to call chrome.notifications.create() in background script and chrome.tabs.executeScript only accept file url or code (css, js) to inject.
And you could check the following items when the notification doesn't show as expected:
Add "notification" to permissions in manifest.json.
"permissions": ["notifications"]
Notifications API only supports Windows, Chrome OS and Mac currently.
The 'option' parameter of create function must include a notification title, message and iconUrl. The rich notification will not work properly without any error if you missed any one of them.
var opt = {
type: "basic",
title: "Primary Title",
message: "Primary message to display",
iconUrl: "url_to_small_icon"
}
Hope this is helpful.
[SOLVED]
i make following changes in code
chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
if (changeInfo.status == 'complete' && tab.active) {
chrome.notifications.create('id1',{
type: 'basic',
iconUrl: 'icon.png',
title: 'Review Baed Surfing',
message: 'Check URL now by clicking FAKE URL icon infront on Address Bar!',
priority: 0
},
function() { /* Error checking goes here */}
);
}
});
Now it works properly.
Thank You,