Office.context.mailbox.item.addFileAttachmentAsync often takes a long time to attach and internal format error occurs - outlook-web-addins

An error occurs when trying to attach a file by calling Office.context.mailbox.item.addFileAttachmentAsync from the Office 365 Outlook add-in (on the web).
This happens frequently right after loading the Outlook website. It may not occur after some time after loading.
It occurs in IE, Chrome (on Windows10, on Mac) and Safari (on Mac). There is no problem with Desktop version.
This has not happened before, but it has recently occurred.
There have been no changes to the Outlook add-in in the last few months.
I created and tested the following simple program. The same error occurs in this program.
Office.initialize = function (reason) {
$(document).ready(function () {
$("#send-btn").click(function () {
try {
var url = "https://www.cloudstoragelight.com/proaxiastorage/f/Demo/TestData.xlsx";
var attachemrtFilename = "TestData.xlsx";
debugger;
Office.context.mailbox.item.addFileAttachmentAsync(
url,
attachemrtFilename,
{ asyncContext: null },
function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed) {
if (asyncResult.error && asyncResult.error.message) {
console.log("Error(" + asyncResult.error.message + ")");
} else {
console.log("Error");
}
}
else {
console.log("SUCCESS");
}
});
} catch (e) {
if (e.message) {
console.log("Error(" + e.message + ")");
} else {
console.log("Error");
}
}
});
});
};
Is there any workaround?
[additional information]
I tried debugging with outlook-web-16.01.debug.js.
Looking at the contents of the stack when an error occurs, there is a _checkMethodTimeout function. The timeout judgment of this function has become true, and Callback has been called.
In this case, Microsoft.Office.Common.ClientEndPoint.invoke function sends the following message in postMessage.
{"_messageType": 0, "_actionName": "ExecuteMethod", "_conversationId": "7cc28a93_6a3c12a5_1581127643048", "_correlationId": 5, "_origin": "https: // localhost: 44313 / MessageRead.html? et =", "_data": {"ApiParams": {"uri": "https://www.cloudstoragelight.com/proaxiastorage/f/Demo/TestData.xlsx", "name": "TestData.xlsx", "isInline": false, "__ timeout __": 600000}, "MethodData": {"ControlId": "963d4dfe-eaad-8e5b-6fa5-3eaac31b660d", "DispatchId": 16}}, "_ actionType": 0, "_ serializerVersion": 1}

Related

Excel JS API displayDialogAsync Error 5001

I'm trying to display a dialog window from my task pane using the Excel JS API. Below is the code and my error message. Attached are screenshots of my manifest file, Add-In Code, and the error message.
function startAuthProcess(){
try {
devserverLog({'DialogApi Check': Office.context.requirements.isSetSupported('DialogApi', '1.1')});
Office.context.ui.displayDialogAsync('https://localhost:3000',
function (asyncResult) {
if (asyncResult.status === 'failed') {
devserverLog(['here is the error message!', asyncResult['error']['code'] + ": " + asyncResult['error']['message'] ]);
} else {
devserverLog('hit success line!');
let dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogEventReceived, __processDialogEvent);
}
});
} catch(e) {
devserverLog({error: e.stack});
}
Screenshot of Code & Manifest File

Electron JS write file permission problems

We are developing an Electron JS app which should get a configuration file from a server at one part. This worked until an hour ago, but now it "magically" throws a permission error. It throws a permission error when we try to write to anything. Here is what we explicitly tested:
app.getPath('userData')
"C:/test"
app.getAppPath()
We tried lauching it from an administrator elevated powershell, but still no success. This is our code snippet:
function canWrite(path, callback) {
fs.access(path, fs.W_OK, function (err) {
callback(null, !err);
});
}
function downloadFile(url, target, target_name) {
canWrite(target, function (err, isWritable) {
if (isWritable){
electronDl.download(
BrowserWindow.getFocusedWindow(),
url,
{
directory: target,
filename: target_name
}
)
console.log("Downloaded from: " + url + " to: " + target);
return true;
} else {
console.log("No permission to write to target");
return false;
}
});
}
downloadFile(REMOTEURL, app.getPath('userData'), 'sessionfile.json');
We rewrote this code, tried to change filenames, tried it without the filename (..) and are a bit out of ideas now. We furthermore implemented a file check (whether the file exists or not) and if so a deletion before executing this. We commented it out for now for debugging because it worked before.
Update:
After somebody pointed out that the outer check is pretty useless, I updated the code to this (still doesn't work):
function downloadFile(url, target) {
electronDl.download(
BrowserWindow.getFocusedWindow(),
url,
{
directory: target,
}
)
}
downloadFile(REMOTEURL, "C:/test");
Since it appears that electron-dl doesn't give clear error messages, you may want to check/create the directory beforehand as you initially did.
The basic procedure could look like this:
Check if the target directory exists.
If it exists, check if it is writable.
If it is writable, proceed to downloading.
If it is not writable, print an informative error message and stop.
If it doesn't exist, try to create it.
If this works, proceed to downloading.
If this fails, print an informative error message and stop.
The following code implements this idea (using the synchronous versions of the fs methods for simplicity). Be sure to use the asynchronous versions if required.
const electronDl = require('electron-dl')
const fs = require('fs')
function ensureDirExistsAndWritable(dir) {
if (fs.existsSync(dir)) {
try {
fs.accessSync(dir, fs.constants.W_OK)
} catch (e) {
console.error('Cannot access directory')
return false
}
}
else {
try {
fs.mkdirSync(dir)
}
catch (e) {
if (e.code == 'EACCES') {
console.log('Cannot create directory')
}
else {
console.log(e.code)
}
return false
}
}
return true
}
function downloadFile(url, target) {
if (ensureDirExistsAndWritable(target) == false) {
return
}
electronDl.download(
BrowserWindow.getFocusedWindow(),
url,
{
directory: target,
}
)
.then(
dl => console.log('Successfully downloaded to ' + dl.getSavePath())
)
.catch(
console.log('There was an error downloading the file')
)
}

Message passing with nested async call in chrome extension fails

This works: Simple message passing with no nested call to chrome API in the onMessage listener.
content_script
chrome.runtime.sendMessage({ message: "what is my windowId?" }, function(response) {
// clearLocalStorage(response.allWindowsId);
windowId = response.windowId;
console.log(windowId);
});
background_script
chrome.runtime.onMessage.addListener(function(request, sender,sendResponse) {
if (request.message === "buttonClick") {
chrome.tabs.reload(sender.tab.id);
sendResponse({message: 'handle button click'});
} else if (request.message === "what is my windowId?") {
sendResponse({
windowId: sender.tab.windowId
});
}
return;
});
This doesnot work: Nested call chrome.windows.getAll in the onMessage listener.
background_script
chrome.runtime.onMessage.addListener(function(request, sender,sendResponse) {
if (request.message === "buttonClick") {
chrome.tabs.reload(sender.tab.id);
sendResponse({message: 'handle button click'});
} else if (request.message === "what is my windowId?") {
// additional code here
chrome.windows.getAll(function(windows) {
sendResponse({
windowId: sender.tab.windowId,
windows: windows
});
});
}
return;
});
I've also tried to make the call chrome.windows.getAll async using chromeExtensionAsync, but no luck yet.
The following is the error message. It seems that the call to window.getAll happens after the function onMessage returns, even though I've marked this function async by the final return; statement.
Error handling response: TypeError: Cannot read property 'windowId' of undefined
Unchecked runtime.lastError: The message port closed before a response was received.
I just published an OSS library that helps with this case: #wranggle/rpc
Take a look at the BrowserExtensionTransport. It includes an example for making remote calls between a content script and the background window.

How to test collabora online performances

I setuped collabora online, and the users complain about performances.
I'd like to be able to graph performances to be able to correlate to other monitoring graphs.
Here is an open document you can access:
https://cloud.pierre-o.fr/s/qnkheXaoBQV97EH
I'd like to be able to time the appearance of the document.
I tried various ways, but it is really tricky.
Here is one attempte with casperjs:
var casper = require('casper').create();
casper.options.waitTimeout = 30000;
casper.start('https://cloud.pierre-o.fr/s/qnkheXaoBQV97EH', function() {
this.waitForSelector('div#StateWordCount', function() {
this.echo('the document is loaded');
}, function _onTimeout(){
this.capture('screenshot.png');
});
})
casper.on("page.error", function(msg, trace) {
this.echo("Error: " + msg, "ERROR");
this.echo("file: " + trace[0].file, "WARNING");
this.echo("line: " + trace[0].line, "WARNING");
this.echo("function: " + trace[0]["function"], "WARNING");
errors.push(msg);
});
casper.run()
As you guess, I just get the screenshot without the document.
phantomjs --version
2.1.1
casperjs --version
1.1.3
I use the recent versions. I guess it is related to websocket, but I'm not sure.
Thanks for your help!
Interesting, this also fails even with a huge timeout
casper.options.viewportSize = { width: 1024, height:800};
casper.test.begin('TEST DOC', 2, function (test) {
casper.start("https://cloud.pierre-o.fr/s/qnkheXaoBQV97EH", function () {
test.assertTitle("Nextcloud");
});
casper.waitUntilVisible("div#StateWordCount", function() {
test.assertExists("Test!", "Found test text");
}, function() {
casper.capture("fail.jpg")
}, 150000);
casper.run(function () {
test.done();
});
});
It shows the following screen:
I would try slimerjs as it looks like it might be a web socket issue!

Calling external function from within Phantomjs+node.js

I'm going to be honest. I'm way in over my head here.
I need to scrape data from a dynamic site for my employer. Before the data is visible on the page, there are some clicks and waits necessary. Simple PHP scraping won't do. So I found out about this NodeJS + PhantomJS combo. Quite a pain to set up, but I did manage to load a site, run some code and get a result.
I wrote a piece of jQuery which uses timeout loops to wait for some data to be loaded. Eventually I get a js object that I want to write to a file (JSON).
The issue I'm facing.
I build up the the js object inside the PhantomJS .evaluate scope, which runs in a headerless browser, so not directly in my Node.JS server scope. How do I send the variable I built up inside evaluate back to my server so I can write it to my file?
Some example code (I know it's ugly, but it's for illustrative purposes). I use node-phantom-simple as a bridge between Phantom and Node
var phantom = require('node-phantom-simple'),
fs = require('fs'),
webPage = 'https://www.imagemedia.com/printing/business-card-printing/'
phantom.create(function(err, ph) {
return ph.createPage(function(err, page) {
return page.open(webPage, function(err, status) {
page.onConsoleMessage = function(msg) {
console.log(msg);
};
console.log("opened site? ", status);
page.evaluate(function() {
setTimeout(function() {
$('.price-select-cnt').eq(0).find('select').val('1266').change()
timeOutLoop()
function timeOutLoop() {
console.log('looping')
setTimeout(function() {
if ($('#ajax_price_tool div').length != 6) {
timeOutLoop()
} else {
$('.price-select-cnt').eq(1).find('select').val('25')
$('.price-select-cnt').eq(2).find('select').val('Premium Card Stock')
$('.price-select-cnt').eq(3).find('select').val('Standard').change()
timeOutLoop2()
}
}, 100)
}
function timeOutLoop2() {
console.log('looping2')
setTimeout(function() {
if ($('.pricing-cost-cnt').text() == '$0' || $('.pricing-cost-cnt').text() == '') {
timeOutLoop2()
} else {
var price = $('.pricing-cost-cnt').text()
console.log(price)
}
}, 100)
}
}, 4000)
});
});
});
});
function writeJSON(plsWrite) {
var key = 'file'
fs.writeFile('./results/' + key + '.json', plsWrite, 'utf8', function() {
console.log('The JSON file is saved as');
console.log('results/' + key + '.json');
});
}
So do do I write the price this code takes from the website, get it out of the evaluate scope and write it to a file?

Resources