Permission denied to access property 'filepicker_comm_iframe' - javascript

Currently facing an issue with Filepicker's iframe in my application... my tools:
Framework: Rails 4 (including turbolinks)
API: Filepicker.io (JS)
File type: Coffeescript
My sample code:
ready = ->
filepicker_api_key = $js_data.data('filepickerApiKey')
unprocessed_path = $js_data.data('unprocessedPath')
filepicker.setKey(filepicker_api_key)
$('#image-upload').click (e) ->
picker_options =
services: ['COMPUTER']
mimetypes: ['image/*']
store_options =
location: 's3'
path: unprocessed_path
access: 'public'
filepicker.pickAndStore picker_options, store_options ->
console.log 'foobar'
# alot of code comes here.. which works whenever I refresh the page
$(document).ready(ready)
$(document).on('page:load', ready)
It stops once I try uploading something. My logs show this error:
Error: Permission denied to access property
'filepicker_comm_iframe'
and doesn't show my 'foobar' log
But when I refresh the page, I receive no error, and the file
uploads accordingly. I am trying to avoid the flaw of having to
refresh the page in order to upload successfully.

Since with turbolinks the body is reloaded, I suggest to move in layout file this code:
<%= filepicker_js_include_tag %>
from <head> to <body>.
It should work fine then (in Rails 4, without installing 'jquery-turbolinks' gem).
In the future we will work on the general solution, independent on where this tag was placed.

I was able to solve this issue, by adding gem 'jquery-turbolinks' to my Gemfile (thus running bundle), and including //= jquery.turbolinks to my application.js.
So far this has been the only valuable work around that I've come across. For this specific scenario.

After loaded, filepicker js add 2 iframes to body. When you use turbolinks to change page, they are gone. So you need to add them again by your self:
if $("#filepicker_comm_iframe").length == 0
$("body").append '<iframe name="filepicker_comm_iframe" id="filepicker_comm_iframe" src="https://dialog.filepicker.io/dialog/comm_iframe/" style="display: none;"></iframe>'
if $("#fpapi_comm_iframe").length == 0
$("body").append '<iframe name="fpapi_comm_iframe" id="fpapi_comm_iframe" src="https://www.filepicker.io/dialog/comm_iframe/" style="display: none;"></iframe>'

Related

How to write a Thunderbird extension (webextension) to modify the message display?

I'd like to write an extension for Thunderbird that modifies the message display (e.g. insert/replace text/markup/image).
Unfortunately, the documentation is lacking (due to recent changes?).
https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Thunderbird_extensions
is outdated
https://developer.thunderbird.net/
does not have useful examples (yet)
https://thunderbird-webextensions.readthedocs.io/
no examples either
Some examples can be found at
https://github.com/thundernest/sample-extensions
Building on https://github.com/thundernest/sample-extensions/tree/master/messageDisplay
I've modified background.js
browser.messageDisplay.onMessageDisplayed.addListener((tabId, message) => {
console.log(`Message displayed in tab ${tabId}: ${message.subject}`);
console.log(message.id);
browser.messages.getFull(message.id).then((messagepart) => {
console.log(messagepart);
body = messagepart['parts'][0]['parts'][0]['body'];
console.log(body);
body += "modified!";
console.log(body);
});
browser.windows.getCurrent().then((window)=>{
console.log(window.type);
});
browser.tabs.getCurrent().then((tab)=>{
console.log("tab",tab);
});
});
which gives me the message body (using magic indexes) but expectedly, the change is not reflected in the message display.
The window type returned is normal, not messageDisplay.
The tab is undefined despite adding permissions
"permissions": [
"messagesRead",
"activeTab",
"tabs",
"tabHide"
],
but I assume that's because the script is running as background.
So I'd need a script running on the content / access to the tab and then some hints on how to modify the displayed message content (I do not want to modify the message).
Where would I find the equivalent documentation to
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts
specific to Thunderbird?
Specifying content_scripts in manifest.json causes "Error: Error reloading addon messageDisplay#sample.extensions.thunderbird.net: undefined".
executeScript() from background does not seem to work either, even with tabId specified.
This was not possible to do when you wrote your question, the API for modifying displayed messages was missing.
As of this writing (September 2020), the browser.messageDisplayScripts API landed a few days ago, see bug 1504475 and related patch for examples. It works as follows: You can register your content script (to modify the displayed messages) like this
let myPromise = browser.messageDisplayScripts.register({
css: [{
file: "/style.css",
}],
js: [{
file: "/content_script.js",
}],
});
And you can later unregister with
myPromise.then((script) => { script.unregister(); });
You need to register the script just once for all messages (you do not need a listener that would load it each time a message is displayed).
Note that your manifest.json needs to include the messagesModify permission for this to work.
The new API will be in Thunderbird version 82, so if I understand the release process correctly it should be in stable version 88 (unless it is backported before that). You can try it already (v82 is the current EarlyBird).
Documentation https://thunderbird-webextensions.readthedocs.io/en/68/tabs.html#getcurrent
says:
May be undefined if called from a non-tab context (for example: a background page or popup view).
Since the background.js is not called from a tab context the tab is undefined.

Rails js-routes: get path

In my rails app I'm trying to make a transition link in my javascript file with help of js-routes gem
$.get(Routes.pay_account_path(self.tour.ID(), {format: 'html'}), function () {
return true;
});
This code seems correct, but there is no transition to path when I click on the button. In browser inspector network I see that http://example.dev/account/38469212-6116-91B2-591C-91D30FBDD6B6/pay.html response is OK

Installing the phonegap facebook plugin

I'm trying to install the phonegap plugin for Facebook by Jos downloadable here: https://github.com/jos3000/phonegap-plugins/tree/master/Android/Facebook
I've got the folder structure set up like this:
src/com/facebook/android/*.java
src/com/hipsnip/plugins/facebook/FacebookAuth.java
src/com/my_app/app/App.java
libs/phonegap-1.0.0.jar
/res/xml/plugins.xml
assets/www/index.html facebook.js phonegap-1.0.0.js
I've added the plugin to the plugin.xml file like so:
<plugin name="facebook" value="com.hipsnip.plugins.facebook.FacebookAuth" />
I've added the facebook.js to my index.html, and have the following function (which gets triggered by pressing a button):
function facebook_login()
{
var appId = "1234"; // this is your facebook app id change me
window.plugins.facebook.authorize(appId,function(res){
alert(res.name);
});
});
});
}
The app opens up a new browser window (I suspect that's what it is) but all it displays is my application without running javascript.
LogCat shows the following error:
file:///android_asset/www/index.html: Line 95 : TypeError: Result of expression 'window.plugins.facebook' [undefined] is not an object.
Thanks for any help you can give (I suspect it has to do with the way that I've set up the folders, or the way I've added the plugin.xml, but I really don't have a clue)!
PhoneGap now has an official Facebook plugin. Use that.

Javascript error in ASP.NET caused by changing from Cassini development server to IIS 7.5 express

I have recently changed from using the cassini development server to IIS 7.5 express, and have found that on some pages my javascript is throwing 'Object doesn't support this property or method' exceptions.
All the pages share the same masterpage which loads all the plugins, and when debugging in the browser the scripts seem to be available.
One particular example is
$(document).ready(function () {
var dlg = $('#<%=PanelAddToList.ClientID%>').dialog({ autoOpen: false, modal: true });
// $('#<%=PanelAddToList.ClientID%> .List-Add').click(function () { __doPostBack('<%=BtnAddToList.UniqueID%>', ''); });
$('#<%=PanelAddToList.ClientID%> .dialog-button-cancel').click(function () { $('#<%=PanelAddToList.ClientID%>').dialog('close'); });
dlg.parent().appendTo(jQuery("form:first"));
});
This is contained in a usercontrol which has PanelAddToList in it. This control works on some pages using IIS but on others it will cause an exception on the 'var dlg =' ... line.
If i switch back to using cassini it all works normally.
Any help would be appreciated, thank you
check if jquery load before not because this type of error occur when they did not find any object.
i think in you case dialog have some error, page can't find dialog method or arguments..

What should I use for the filepath if I'm developing from my desktop?

I'm having an extremely difficulty time getting the flowplayer to show up and the worst part is I have no idea what is wrong because I'm not getting any error messages!
I have an external javascript file:
C:/desktop/mysite/js/jq/plugins.js
calling $f() from:
C:/desktop/mysite/thirdparty/flowplayer/flowplayer.js
the swf files also live there...
I'm working on file/desktop (no localhost or webserver)
$(video.id).flowplayer("thirdparty/flowplayer/flowplayer-3.1.15.swf", {
clip:{
....
},
// min Flash version
version:[9,115],
// older versions will see a custom message
onFail:function(){
alert("Failed!");
},
onError:function(errCode,errMsg){
alert(errCode+errMsg);
}
});
I don't know what path to use for the SWFs to get them to load, is the path relative to the javascript (plugins.js) that calls $f() or is it relative to the path of the flowplayer.js ??
bangs head on wall
Why not use the absolute path?
$(video.id).flowplayer("file://c:/desktop/mysite/thirdparty/flowplayer/flowplayer-3.1.15.swf"...
replace thirdparty/flowplayer/flowplayer-3.1.15.swf with thirdparty\flowplayer\flowplayer-3.1.15.swf
if you are planning to put that on a web page then change the slashes back to forward slashes.

Categories