From 16353c346670980ca993633624dd4f75ba17ca94 Mon Sep 17 00:00:00 2001 From: Vladimir Kotikov Date: Tue, 24 Mar 2015 18:11:28 +0300 Subject: [PATCH] CB-8661 Return executed script result on Windows --- README.md | 4 ++++ src/windows/InAppBrowserProxy.js | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47bbac0..274dc94 100644 --- a/README.md +++ b/README.md @@ -349,6 +349,10 @@ The function is passed an `InAppBrowserEvent` object. - only __code__ key is supported. +### Windows Quirks + +Due to [MSDN docs](https://msdn.microsoft.com/en-us/library/windows.ui.xaml.controls.webview.invokescriptasync.aspx) the invoked script can return only string values, otherwise the parameter, passed to __callback__ will be `[null]`. + ## insertCSS > Injects CSS into the `InAppBrowser` window. diff --git a/src/windows/InAppBrowserProxy.js b/src/windows/InAppBrowserProxy.js index da5eb82..d31be2d 100644 --- a/src/windows/InAppBrowserProxy.js +++ b/src/windows/InAppBrowserProxy.js @@ -242,7 +242,10 @@ var IAB = { if (isWebViewAvailable && browserWrap && popup) { var op = popup.invokeScriptAsync("eval", code); - op.oncomplete = function () { hasCallback && win([]); }; + op.oncomplete = function (e) { + var result = [e.target.result]; + hasCallback && win(result); + }; op.onerror = function () { }; op.start(); } @@ -261,7 +264,10 @@ var IAB = { Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri).done(function (file) { Windows.Storage.FileIO.readTextAsync(file).done(function (code) { var op = popup.invokeScriptAsync("eval", code); - op.oncomplete = function () { hasCallback && win([]); }; + op.oncomplete = function(e) { + var result = [e.target.result]; + hasCallback && win(result); + }; op.onerror = function () { }; op.start(); });