SelectionContext in iFrame - Permission denied to access property 'getSelection'

On sites with iFrames I have difficulties retrieving the selected text if I take a detour via a context-menu content-script.

In main.js I define a context-menu-item with a SelectionContext, in its onMessage-method a page-mod contentScriptFile is informed. This script is then supposed to get the selection via getSelection().toString().

But when being inside an iFrame this method either returns an empty string or getSelection is null. Trying to get the selection via parent window (parent.getSelection()) results in an error (probably due to Same-Origin-Policy):

console.error: Message: Error:
Permission denied to access property “getSelection”

Anyone any idea how to solve this issue? Thanx

1 Like

I’m not sure if it is same origin policy BUT if it is, this MIGHT help.

Try adding to package.json something like this:

  "permissions": {
     "cross-domain-content": ["https://data.com"]
  }

If that doesn’t work check out the documetnation on permissions for package.json it might have something that will help.

Another place you can look for help is GitHub - see how other people used SelectionContext - https://github.com/search?utf8=✓&q=sdk+SelectionContext&type=Code&ref=searchresults

The solution in this particular case was to add an attachTo-method to the page-mod:
attachTo: [‘top’]

(answer from stackoverflow)

1 Like