Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Error thrown when trying to take a Screenshot on Firefox with an iFrame in focus #3512

Open
nwestrum opened this issue Dec 7, 2022 · 1 comment

Comments

@nwestrum
Copy link

nwestrum commented Dec 7, 2022

When a test fails and takes a screenshot or if you call the saveScreenshot function directly and you are on Firefox, you will get an error from Geckodriver:

Error
     Response 500 GET /session/97e7684a-f42d-45f0-9428-5f957de28cc4/screenshot (3ms)
   {
     value: {
       error: 'unknown error',
       message: 'SecurityError: Permission denied to access property "pageXOffset" on cross-origin object',
       stacktrace: ''
     }
  }
    Error   Error while running .getScreenshot() protocol action: SecurityError: Permission denied to access property "pageXOffset" on cross-origin object

  Error

This screenshot is taken just fine when running Chrome, and with Firefox all you have to do is travel below to the parent frame before you try to take the screenshot. I think if we just add this line or something similar right before we take the screenshot it will travel to the Parent Frame and have no affect on Chrome or other browsers:

    if(this.api.options.desiredCapabilities.browserName == 'firefox') {
      this.api.frameParent()
    }

right before

this.api.screenshot(this.api.options.log_screenshot_data, function(result) {

Note: One thing that could happen is if you are in an iFrame it will bring you to the parent if you call the function directly, so you will have to go back to the Frame if you want to continue to test within it. Some way of detecting whether you are in a frame or not could be added to automatically move you back into the frame after taking the screenshot would be ideal.

Here is the logs of the code running on Firefox successfully:

 → Running command: saveScreenshot ('./tests_output/screenshots/firefoxTest.png')
 
 → Running command: frameParent ()
   Request POST /session/9b9ab34c-28af-4b37-9f25-7c04d1d00a3e/frame/parent  
{}
   Response 200 POST /session/9b9ab34c-28af-4b37-9f25-7c04d1d00a3e/frame/parent (3ms)
   { value: null }
  → Completed command: frameParent () (3ms)
 
 → Running command: screenshot (false, [Function])
   Request GET /session/9b9ab34c-28af-4b37-9f25-7c04d1d00a3e/screenshot  

   Response 200 GET /session/9b9ab34c-28af-4b37-9f25-7c04d1d00a3e/screenshot (118ms)
   {
     value: 'iVBORw0KGgoAAAANSUhEUgAACgAAAATpCAYAAAAcIErPAAAgAElEQVR4XuydB3hURReGT3rooRepCiJNihRFRJr0qjRBpSq9ifTe...',
     suppressBase64Data: true
  }
  → Completed command: screenshot (false, [Function]) (171ms)
  → Completed command: saveScreenshot ('./tests_output/screenshots/firefoxTest.png') (183ms)

Sample test:
launch with a firefox browser config with screenshots save on failure:

'Handling Nested iFrames': function (browser) {
    browser
      .url('https://the-internet.herokuapp.com/nested_frames')
      .frame(1)
      .saveScreenshot('./testScreenshot')
      .frame(2)
      .assert.containsText('#content', 'MIDDLE') //failure assert to test the save screenshot on failure
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants