-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bidi][js] Update the capture screenshot APIs to include all paramete…
…rs and remove scroll parameter (#13744)
- Loading branch information
Showing
4 changed files
with
200 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
javascript/node/selenium-webdriver/bidi/captureScreenshotParameters.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
const { BoxClipRectangle, ElementClipRectangle } = require('./clipRectangle') | ||
const Origin = { | ||
VIEWPORT: 'viewport', | ||
DOCUMENT: 'document', | ||
} | ||
|
||
class CaptureScreenshotParameters { | ||
#map = new Map() | ||
|
||
origin(origin) { | ||
if (origin !== Origin.VIEWPORT && origin !== Origin.DOCUMENT) { | ||
throw new Error(`Origin must be one of ${Object.values(Origin)}. Received:'${origin}'`) | ||
} | ||
this.#map.set('origin', origin) | ||
return this | ||
} | ||
|
||
imageFormat(type, quality = undefined) { | ||
if (typeof type !== 'string') { | ||
throw new Error(`Type must be an instance of String. Received:'${type}'`) | ||
} | ||
|
||
this.#map.set('type', type) | ||
|
||
if (quality !== undefined) { | ||
if (typeof quality !== 'number') { | ||
throw new Error(`Quality must be a number. Received:'${quality}'`) | ||
} | ||
this.#map.set('quality', quality) | ||
} | ||
return this | ||
} | ||
|
||
clipRectangle(clipRectangle) { | ||
if (!(clipRectangle instanceof BoxClipRectangle || clipRectangle instanceof ElementClipRectangle)) { | ||
throw new Error(`ClipRectangle must be an instance of ClipRectangle. Received:'${clipRectangle}'`) | ||
} | ||
this.#map.set('clip', Object.fromEntries(clipRectangle.asMap())) | ||
return this | ||
} | ||
|
||
asMap() { | ||
return this.#map | ||
} | ||
} | ||
|
||
module.exports = { CaptureScreenshotParameters, Origin } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Licensed to the Software Freedom Conservancy (SFC) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The SFC licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
class ClipRectangle { | ||
clipType | ||
|
||
constructor(type) { | ||
this.clipType = type | ||
} | ||
|
||
get type() { | ||
return this.clipType | ||
} | ||
|
||
asMap() {} | ||
} | ||
|
||
class ElementClipRectangle extends ClipRectangle { | ||
#sharedId | ||
#handleId | ||
|
||
constructor(sharedId, handleId = undefined) { | ||
super('element') | ||
this.#sharedId = sharedId | ||
|
||
if (handleId !== undefined) { | ||
this.#handleId = handleId | ||
} | ||
} | ||
|
||
asMap() { | ||
const map = new Map() | ||
map.set('type', super.type) | ||
|
||
const sharedReference = new Map() | ||
sharedReference.set('sharedId', this.#sharedId) | ||
if (this.#handleId !== undefined) { | ||
sharedReference.set('handleId', this.#handleId) | ||
} | ||
|
||
map.set('element', Object.fromEntries(sharedReference)) | ||
|
||
return map | ||
} | ||
} | ||
|
||
class BoxClipRectangle extends ClipRectangle { | ||
#x | ||
#y | ||
#width | ||
#height | ||
|
||
constructor(x, y, width, height) { | ||
super('box') | ||
this.#x = x | ||
this.#y = y | ||
this.#width = width | ||
this.#height = height | ||
} | ||
|
||
asMap() { | ||
const map = new Map() | ||
map.set('type', super.type) | ||
map.set('x', this.#x) | ||
map.set('y', this.#y) | ||
map.set('width', this.#width) | ||
map.set('height', this.#height) | ||
|
||
return map | ||
} | ||
} | ||
|
||
module.exports = { BoxClipRectangle, ElementClipRectangle } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters