Using dojo 1.8 in a packaged app (uncaught unload is not available in packaged apps)

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

After finally making some progress in using dojo with my packaged app, I've hit another road block that I can't find any documentation for.

{   ...   "sandbox": {      "pages": ["test.html"]   },   "app": {     "background": {       "scripts": [         "background.js"       ]     }   } } 

test.html loads dojo from the app as well as some of my modules, but as dojo parses the dom of the page, I get an error thrown by the platformApp

Uncaught unload is not available in packaged apps. platformApp:14 (anonymous function)                               platformApp:14 Window.addEventListener                            platformApp:127 addListener                                        dojo.js.uncompressed.js:15317 on.parse 

Are there any CSP rules I can add to the sandbox to let this do it's normal thing?

回答1:

I wish that chrome did this by default instead of throwing an error... but this is what I had to do before I loaded dojo:

// Prevent registrations for unload/beforeunload and warn, chrome will throw exception. (function() {   var windowAddEventListener = Window.prototype.addEventListener;   Window.prototype.addEventListener = function(type) {     if (type === 'unload' || type === 'beforeunload') {           try {         throw new Error('Do not use Window.addEventListener for ' + type);       } catch (e) {         console.error(e.message, e);       }     } else       return windowAddEventListener.apply(window, arguments);   }; })(); 


回答2:

As the error message states, load and beforeload methods are disabled for packaged apps, and that applies to sandboxed iframes as well. You can check what else is disabled here.

Having said that, I just tried dojo 1.8 in a sandboxed iframe and, as long as I don't set unload listeners, the simple Hello Dojo sample seems to work fine.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!