最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firefox - How can I call window.wrappedJSObject.somePromise in window.Promise? - Stack Overflow

programmeradmin1浏览0评论

I want to avoid postMessage between webextension and tab app in firefox because of low privacy.

But I've encountered permission wall.

// content script in webextension
const obj = new window.Object()

 // It's OK
obj.good = exportFunction(() => {
  return window.wrappedJSObject.somePromiseFunc();
}, window);

// NG calling then of somePromiseFunc
obj.ng = exportFunction(() => {
  return window.wrappedJSObject.somePromiseFunc().then(val => {
      val
    }) // Uncaught (in promise) Error: Permission denied to access object
})

// NG wrapped by window.Promise either
obj.foo = exportFunction(() => {
  return new window.Promise(resolve => {
    window.wrappedJSObject.object // It's OK
    window.wrappedJSObject.somePromiseFunc().then(val => {
      resolve(val)
    }) // Uncaught (in promise) Error: Permission denied to access object
  })
})

The method for success described Webextension Content script return Promise to page-script in 2017 didn't work either.

The same error:

obj.foo = exportFunction(() => {
  return new window.wrappedJSObject.Promise(
    exportFunction(function (resolve) {
        window.wrappedJSObject.somePromiseFunc().then(val => {
          resolve(val)
        }) // Uncaught (in promise) Error: Permission denied to access object
    }, window.wrappedJSObject)
  )
}, window.wrappedJSObject)

I want to call window.wrappedJSObject.somePromiseFunc() with function passed from content script. Is there any way?

发布评论

评论列表(0)

  1. 暂无评论