I'm troubleshooting an issue where a pop-up created by an Outlook add-in isn't communicating to its parent when using Office.context.ui.messageParent() in the Outlook desktop client for Windows.
The issue started occurring after a Windows 10 update (1903). The Outlook desktop client version I'm using is: 16.0.12026.20344. I'm loading the Office JS Api through the CDN provided in their Github repo.
Initially, I thought it was a lack of registering the correct events on the pop-up window but the event raised (dialogEventReceived) when the pop-up window is closed is registered and handled correctly.
There are no logged errors after calling Office.context.ui.messageParent().
I've made sure that the pop-up window (handling authentication in this case) is correctly loading the Office JS api and is initializing.
All applicable app domains have been correctly listed in the add-in's manifest file.
Office.context.ui.displayDialogAsync(fullUrl,
{
height: 60,
width: 20,
displayInIframe: false
}, function (asyncResult) {
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
//showNotification(asyncResult.error.code = ": " + asyncResult.error.message);
} else {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
dialog.addEventHandler(Office.EventType.DialogEventReceived, processDialogEvent);
}
});
Office.initialize = function() {
console.log('oauth2 redirect');
debugger;
Office.context.ui.messageParent(window.location.href);
};
The expected behavior is that the pop-up raises the dialogMessageReceived event.
Related
I am trying to develop a simple web extension/addon under Safari, which is using the tabs onUpdated event. I used the Safari XCRUN converter: https://developer.apple.com/documentation/safariservices/safari_web_extensions/converting_a_web_extension_for_safari
What I am trying to do is :
Open new tab on Google Scholar with set prefs params, from "options.js" script (Options page code below)
Listen for this tab to be updated and ready (e.g. tab status is complete)
Then, inject a content script that will simulate the user click on save button (i.e. on GScholar page)
Then remove the listener, and wait 1,5s (for GS tab to reload and finish saving) in order to finally close this tab.
// Detect browser language
const gsUrl = currentBrowser.i18n.getUILanguage().includes("fr")
? GSCHOLAR_SET_PREFS_FR_URL
: GSCHOLAR_SET_PREFS_COM_URL;
// Listener to detect when the GS tab has finished loading
const gsTabListener = (tabId, changeInfo, tabInfo) => {
if (changeInfo.url && changeInfo.url.startsWith(GSCHOLAR_HOST)) {
currentBrowser.tabs.executeScript(
tabId,
{
code: `document.getElementsByName("save")[0].click();`,
},
() => {
currentBrowser.tabs.onUpdated.removeListener(gsTabListener);
setTimeout(() => currentBrowser.tabs.remove(tabId), 1500);
}
);
}
};
currentBrowser.tabs.onUpdated.addListener(gsTabListener); // Add tab listener
currentBrowser.tabs.create({
url: `${gsUrl}?inst=${gScholarInstIdList.join("&inst=")}&save=#2`,
active: false,
}); // Open GS tab according to browser language
The problem is that it works well on Chrome/Edge/Firefox (on MacOS), but not on Safari : the GS tab is opended but isn't closed and nothing happens :-/
PS:
It seems tabs onUpdated event is well supported on Safari according to MDN.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated
I have also tried webNavigation onCompleted event, but same !
Developing on : MacBookAir under MacOS Monterey 12.4, Safari 15.4 (17613.2.7.18), XCode 13.3.1 (13E500a), extension is bundled with Webpack 5.68.0 (e.g. building all assets files).
I really don't see what I am doing wrong and why wouldn't this tab event be intercepted ?
Thanks for your feedback.
After debugging I finally sloved this by noticing that in fact the events were triggered, but missed because of the availability and values of parameters passed into callabck (changeInfo, details) depending on the browser we're on.
So I switched from onUpdated to webNavigation.onCompleted API, which is better suited to our need (tab page fully loaded) and whose parameter is simple and consistent across browsers :-)
const uiLanguage = currentBrowser.i18n.getUILanguage().includes("fr")
? "fr"
: "com"; // Detect browser language
const gsUrl = `${GSCHOLAR_SETTINGS_HOST}.${uiLanguage}`;
// Listener to detect when the GS tab has finished loading
const gsTabListener = (details) => {
if (details && details.url && details.tabId) {
if (details.url.startsWith(`${gsUrl}/scholar_settings?`)) {
currentBrowser.tabs.executeScript(details.tabId, {
code: `document.getElementsByName("save")[0].click();`,
});
} else if (details.url.startsWith(`${gsUrl}/scholar?`)) {
currentBrowser.webNavigation.onCompleted.removeListener(
gsTabListener
);
currentBrowser.tabs.remove(details.tabId);
}
}
};
currentBrowser.webNavigation.onCompleted.addListener(gsTabListener); // Add GS tab listener
currentBrowser.tabs.create({
url: `${gsUrl}/scholar_settings?inst=${gScholarInstIdList.join(
"&inst="
)}&save=#2`,
active: false,
}); // Open GS tab according to browser language
I'm trying to develop a Firefox add on using WebExtensions. What I'm trying to do is open a new Firefox tab or window when the user clicks the notification. But it doesn't work.
When I click the notification, nothing happens.
I'm creating notifications like:
var q = chrome.notifications.create({
"type": "basic",
"iconUrl": chrome.extension.getURL("128-128q.png"),
"title": 'title',
"message": 'content'
});
chrome.notifications.onClicked.addListener(function(notificationId) {
window.open('http://www.google.com');
});
browser.notifications.onClicked.addListener(function(notificationId) {
window.open('http://www.google.com');
});
q.onClicked.addListener(function(notificationId) {
window.open('http://www.google.com');
});
var audio = new Audio('message.mp3');
audio.play();
How can I make this work?
It appears that the problem is that you are attempting to open a new URL in a way that does not work.
The following should work, using chrome.tabs.create():
var q = chrome.notifications.create("MyExtensionNotificationId", {
"type": "basic",
"iconUrl": chrome.extension.getURL("128-128q.png"),
"title": 'title',
"message": 'content'
});
chrome.notifications.onClicked.addListener(function(notificationId) {
chrome.tabs.create({url:"http://www.google.com"});
});
However, you need to be testing this in Firefox 47.0+ as support for chrome.notifications.onClicked() was only added recently. My statement of Firefox 47.0+ is based on the compatibility table. However, the compatibility table has at least one definite error. Thus, a higher version of Firefox may be required. The code I tested worked in Firefox Nightly, version 50.0a1, but did not work properly in Firefox Developer Edition, version 48.0a2. In general, given that the WebExtensions API is in active development, you should be testing against Firefox Nightly if you have questions/issues which are not functioning as you expect. You can also check the source code for the API to see what really is implemented and when it was added.
Note: this works with either chrome.notifications.onClicked or browser.notifications.onClicked. However, don't use both to add two separate anonymous functions which do the same thing as doing so will result in whatever you are doing happening twice.
I did not actually test it with your code, but I did test it with a modified version of the notify-link-clicks-i18n WebExtensions example. I modified the background-script.js file from that example to be:
/*
Log that we received the message.
Then display a notification. The notification contains the URL,
which we read from the message.
*/
function notify(message) {
console.log("notify-link-clicks-i18n: background script received message");
var title = chrome.i18n.getMessage("notificationTitle");
var content = chrome.i18n.getMessage("notificationContent", message.url);
let id = "notify-link-clicks-i18n::" + title + "::" + message.url;
chrome.notifications.create(id,{
"type": "basic",
"iconUrl": chrome.extension.getURL("icons/link-48.png"),
"title": title,
"message": content
});
}
/*
Assign `notify()` as a listener to messages from the content script.
*/
chrome.runtime.onMessage.addListener(notify);
//Add the listener for clicks on a notification:
chrome.notifications.onClicked.addListener(function(notificationId) {
console.log("Caught notification onClicked with ID:" + notificationId);
//Open a new tab with the desired URL:
browser.tabs.create({url:"http://www.google.com"});
});
My preference for something like this where a unique ID is possible is to provide a unique ID, that both identifies that the notification was displayed by my add-on and what the notification was. This allows the listener function to choose to only act on notifications which were displayed by my add-on and/or only a subset of those I display, or have different actions based on why I displayed the notification.
The reason you had trouble here in figuring out what was not working is probably because you did not reduce the issue to the minimum necessary to demonstrate the issue. In other words, it would have been a good idea to just try opening a new URL separately from the notifications onClicked listener and just try a console.log() within the listener.
I have a Firefox add on that displays a pop-up when it sees a certain response header. This works fine when I have a single window. However, when I have multiple windows open, and one of the tabs in a window triggers the pop-up code in my add-on (due to the presence of said header) I get a pop-up in each of my open windows. For example, if I have 3 windows open, I get 3 different pop ups, one for each windows. Is this the default behavior, and is there an easy in-built way to fix this using their SDK.
Edit:
I have the following code:
Util.requestBlock(httpChannel) {
/*load response headers here*/
if (responseHeaders.includes("header_xyz"))
alert("show popup");
}
Util.monitor = function(w) {
this.obsService = Components.classes['#mozilla.org/observer-service;1'].getService(Components.interfaces.nsIObserverService);
this.obsService.addObserver(this, 'http-on-examine-response', false);
}
Util.monitor.prototype = {
'observe': function(subject, topic, data). {
if (topic == 'http-on-examine-response'). {
var channel = subject.QueryInterface(Components.interfaces.nsIHttpChannel);
var block_response = new Util.RequestBlock(channel);
}
},
};
The Util.monitor adds an observer. Whenever a response is received, the "Observe" function is called.
var windows = require("window-utils");
for (window in windows.browserWindowIterator)
doToWindow(window);
Are there any windows software that i can use that can connect with my website via API where there is a customizable feature for desktop notifications?
Alternatively, are there any hacks i can use to make the width of the chrome desktop notification larger?
I tried using html but this just prints as a string.
function notifyMe() {
if (!Notification) {
alert('Notifications are supported in modern versions of Chrome, Firefox, Opera and Firefox.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
var notification = new Notification('Notification title', {
icon: 'http://www.metoffice.gov.uk/media/image/j/i/Cumulus_2.jpg',
body: "<div style='width:700px'>You've been notified!</div>",
});
notification.onclick = function () {
window.open("http://www.google.com");
};
}
Any suggestions.. i want a customizable size notification?
You can't change the size of Chrome-provided notifications.
You can use an extension + Native Messaging to pass something to a native application of your choice (maybe through a "proxy" script, as Native Messaging is limited).
I am trying my first Phonegap application for Windows Phone 7.
I have installed Windows Mobile SDK 7.1 (including emulator, VS2010 for Win Phone, XNA, e.t.c.) on a Windows 7 Pro workstation as well as Phonegap 3.4.0 (which contains the wp7 platform) via NodeJS.
I have created my first project with phonegap command from the command line (phonegap create ...).
I have added the wp7 platform also with the phonegap command (phonegap build wp7).
I have opened the created project in VS2010 for Win Phone in order to run it on the emulator.
... everything runs ok so far = the app starts on the emulator ... (remember it is the Phonegap default sample application)
However if I add the following code in the handling function riggered on deviceready event it seems to hang:
...
console.log('call document.addEventListener("backbutton")');
document.addEventListener("backbutton", onBackButton,false);
console.log('end document.addEventListener ok');
...
The first log output is executed but the second log output does not appear. It seems it hangs on addEventListener("backbutton",...) ... If I comment this line out I get both log outputs.
Here is the relevant part of the code:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
// Bind any events that are required on startup. Common events are:
// `load`, `deviceready`, `offline`, and `online`.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
// The scope of `this` is the event. In order to call the `receivedEvent`
// function, we must explicity call `app.receivedEvent(...);`
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
console.log('call document.addEventListener("backbutton")');
document.addEventListener("backbutton", this.onBackButton,false);
console.log('end document.addEventListener ok');
},
onBackButton: function() { }
};
Output:
Received Event: deviceready
call document.addEventListener("backbutton")
According to Phonegap documentation the "backbutton" event is supported on Windows 7: http://docs.phonegap.com/en/3.4.0/cordova_events_events.md.html#backbutton
UPDATE:
I have found out that I need to use the context 'this', so I have corrected to:
document.addEventListener('backbutton', this.onBackButton ,false);
... however it did not work either. On the other hand if I try to register a different event, f.x. 'click' it works fine, i.e. the execution goes further as it should (I get the second log output) and I get the event when I click on the document.
document.addEventListener('click', this.onBackButton ,false);
Does anybody have an idea, suggestion or solution?
UPDATE 2:
Adding some more debug output via a function like:
window.onerror = function(message, file, line)
{
console.log('error on ' + file + ' at ' + line + ': ' + message);
}
I get the following extra error:
error on x-wmapp1:/app/www/cordova.js at 827: 'ArrayBuffer' is undefined
I have no idea what is the connection between addEventListener('backbutton') and ArrayBuffer but it looks like a bug in cordova !? ... or ... that ArrayBuffer is not defined in Windows Phone SDK 7.1 !?
Have anybody meet this before?
Thank you
Radu