Event Handler for Outlook Add-in dialog box is failing - outlook-web-addins

I have add-in that calls a dialog box from an Outlook task pane. The Dialog is loading properly but the parent task pane is not receiving any data from the Dialog even though the dialog has the messageParent script on it. It seems that the event handler in the parent task pane is not executing at all.
I am using Outlook 2013 and also via Outlook.com. Both environments are displaying the same behaviour.
This is the code I have in the parent task pane:
var dlg;
Office.initialize = function (reason) {
$(document).ready(function () {
$("#btnTestDialog").click(function () {
Office.context.ui.displayDialogAsync("https://localhost:44300/TestDialog.aspx",
{ height: 50, width: 25, displayInIframe: true },
function (result) {
dlg = result.value;
dlg.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, processTestDialog);
});
});
});
};
function processTestDialog(result) {
var x = "";
dlg.close();
}
This is my code from my Dialog page (TestDialog.aspx)
Office.initialize = function (reason) {
$('#btnTest').click(passDataToTest);
$(document).ready(function () {
});
};
function passDataToTest() {
var response = { "status": "sucess", "message": "test" };
Office.context.ui.messageParent(JSON.stringify(response));
}
I have done a lot of research and in all my research it is saying that this code should work but I have no idea why it is not.

Related

Unchecked runtime.lastError: No tab with <id>, Chrome Extension

I don't understand why i recieve this error
Error
This code works
chrome.tabs.onUpdated.addListener(handleUrls);
function handleUrls(tabId, { changeInfo }, tab) {
const isOauthTokenPage = tab.url?.match(CONFIG.OAUTH_TOKEN_PAGE_PATTERN);
if (isOauthTokenPage) {
chrome.tabs.remove(tabId);
}
}
But why i get this error?
I tried chrome.tabs.onUpdated.removeListener before and after chrome.tabs.remove(tabId), tried chrome.tabs.query to get "actual" tabId
So it's trigger more than once
To avoid it
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// check url state
if (!changeInfo.url) return;
// your code...
if ((tab.url).match(CONFIG.OAUTH_TOKEN_PAGE_PATTERN)) {
// won't invoke onUpdated several times
chrome.tabs.remove(tabId);
}
});

window object in NodeJS of SSR got both 'not defined' or 'already been declared'

I am migrating an Angular 6 project to Angular Universal project(SSR). In my project, I need to access window object in order to get "navigator", "location", etc... I am using the following method to polyfill window in Server side. But it is not working.
try {
console.log(window);
} catch (window) {
console.log('Server side window.');
window = {
location: {
replace: () => {},
protocol: 'https'
},
navigator: {
userAgent: '',
appVersion: ''
},
scrollTo: () => {},
open: () => {},
localStorage: {}
};
console.log('Server side window.', window);
}
What is the best way to handle the window object properly on the server side for the server-side rendering web site? I got following confusion errors. It said 'window is not defined' or 'has been declared'. How to use window object in NodeJS?
> console.log(window);
ReferenceError: window is not defined
> let window = 1
SyntaxError: Identifier 'window' has already been declared
The problem with this piece of code is that window is specified as exception identifier in try..catch, basically:
try {
console.log(window);
} catch (window) {
// window instanceof ReferenceError
window = {...};
// window is redefined in this block scope
}
This will work in loose mode:
try {
console.log(window);
} catch (err) {
window = {...};
}
But will result in another ReferenceError in strict mode. It should be instead:
try {
console.log(window);
} catch (err) {
global.window = {...};
}
And a proper way to detect window is:
if (typeof window === 'undefined') {
global.window = {...};
}
This code is limited to browser and Node.js; it will result in an error in a worker.

How to Get Window Variable Using WebdriverIO

I am trying to run webdriverio with PhantomJS/Chrome to load a page and then grab the window object for use with other scripts. For some reason I am unable to get the window object. Everytime I get, I end up seeing output like this:
Title is: XXXXX
{ state: 'pending' }
Using the following script:
var webdriverio = require('webdriverio');
var options = {
desiredCapabilities: {
browserName: 'chrome',
logLevel: 'verbose'
}
};
var client = webdriverio.remote(options);
client
.init()
.url('https://xxxx.com')
.waitUntil(function () {
return client.execute(function () {
return Date.now() - window.performance.timing.loadEventEnd > 40000;
}).then(function (result) {
console.log(window);
return window;
});
})
.end();
Does anyone know how I can fix my code so that the window object is returned to my NodeJS console app after the page is completely loaded?
Thanks!
Window is an object in the browser's DOM, so it's only available inside of the 'execute' function. If you wanted access to it, you could return it from your 'execute' function:
return client.execute(function () {
return window;
}).then(function (result) {
console.log(result);
});
This work as well:
browser.execute('return window');

socket.io and ui-router change state

I found some question about this, but no proper solution.
I want to accomplish something looks theoretically simple:
I have 2 views (ui-router states):
"list" that shows a list of documents with "edit" button. Clicking on the button you go to the editor.
"editor" that shows a form for edits a single document.
If an user visits the 'editor' I want to send a message to the "list" view and disable the edit button.
So what I'm trying to do is a simple websocket way to disable the access in write to documents that are in editing (just in frontend).
One of the problems come when I change route. The socket stop working. The idea is open a socket connection when I join the "list" view and disconnect when I leave it to any other route (including "editor"); the same with "editor" view. Below the code, but it doesn't work.
Following this idea, when the user clicks on the edit button (leave the 'list' view to the join the 'editor' view) I have to deal with a rapid disconnection (list view)-connection(editor view) in immediate sequence (I guess I cannot be sure about the sequence of the socket events..)
server-side
var lockedList = [];
io.on('connection', function (socket) {
console.log('a user connected:'+socket.id);
socket.emit('user:get',socket.id);
socket.emit('doc:list', lockedList);
socket.on('disconnect', function (s) {
console.error('a user disconnected:'+socket.id);
lockedList = lockedList.filter(function(el) {
return el.client !== socket.id;
});
socket.broadcast.emit('doc:list',lockedList);
socket.removeAllListeners('doc:list'); //?
socket.removeAllListeners('disconnect');
});
socket.on('doc:lock', function (obj) {
console.error('doc:lock:');
console.error(obj);
lockedList.push(obj);
socket.broadcast.emit('doc:list',lockedList);
});
socket.on('doc:unlock', function (obj) {
console.error('doc:unlock:');
console.error(obj);
lockedList = lockedList.filter(function(el) {
return el.client !== socket.id;
});
socket.broadcast.emit('doc:list',lockedList);
socket.disconnect();
});
socket.on('doc:list', function () {
console.log('doc:list')
socket.broadcast.emit('doc:list',lockedList);
});
socket.on('doc:askList', function () {
console.log('doc:askList')
socket.broadcast.emit('doc:list',lockedList);
});
socket.on('user:disconnect', function () {
console.log('user:disconnect')
socket.broadcast.emit('doc:list',lockedList);
socket.disconnect();
});
the "live" array of locked documents I want to keep server-side is in the form:
lockedList = [
{"client":"TourJX6zem1MpCx8AAAH","document":"580e899ca9c8621c48c0042d"}
]
keep the client socketId is necessary because I can't figure it out a better way to unlock a document an user stop editing (the user save the edits to the document or just close the browser/tab without save).
"List" angular controller
socket.on('connect', function () {
socket.emit('doc:askList', function () {});
});
socket.on('user:get', function (clientid) {
console.log("(list)here your socked id: " + clientid);
});
socket.on('doc:list', function (list) {
$scope.lockedList = list;
});
$scope.$on('$stateChangeStart', function (event, next) {
socket.disconnect();
});
$scope.$on('$destroy', function (event) {
socket.disconnect();
});
"Editor" angular controller
socket.on('connect', function () {
console.log("editor_connect");
});
socket.on('user:get', function (clientid) {
console.log("here your socked id: " + clientid);
$scope.clientid = clientid;
$scope.message = { client: clientid, document: $scope.model._id }; //$scope.model._id is the document id: once I have the client connection Id, I a emit doc:lock with the clientId and the documentId
socket.emit('doc:lock', $scope.message);
});
$scope.$on('$stateChangeStart', function (event, next) {
socket.disconnect();
});
$scope.$on('$destroy', function (event) {
socket.disconnect();
});
Last note: to solve the $apply issue, I use the socketio angular Service posted here https://stackoverflow.com/a/17092745/3671995

Exiting CommandDialog by a user

I'm trying to find a way exiting a CommandDialog dialog by a user when using back or cancel or otherwise changes their mind.
var startCommands = new builder.CommandDialog();
bot.add('/', [
function (session, results) {
session.send('Hello %s', session.userData.name);
// starting a dialog based on CommandDialog
session.beginDialog('/begin');
},
function (session, results) {
// This is where I want to be when dialog cancel of back is initiated by a user inside /begin
session.send("you are back at the main dialog, start finshing process")
session.beginDialog('/finish');
}
]);
// defining a dialog for CommandDialog class
bot.add('/begin', startCommands)
bot.add('/finish', finishCommands)
startCommands.matches('yo', [
function (session) {
session.send('yo-yo');
}
]);
startCommands.matches('tu', [
function (session) {
session.send('tu-tu');
}
]);
startCommands.matches('.*', [
function (session) {
session.send('any-any');
session.endDialog();
}
]);
To exit a dialog, CommandDialog or otherwise, use a triggerAction on a dialog handler that calls session.endConversation().
For example, here is an exit dialog which ends the conversation when the user sends the message exit or quit.
bot.dialog('exit', function (session) {
session.endConversation('Goodbye!');
}).triggerAction({ matches: /(quit|exit)/i });

Resources