mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: migrate src/EmulationManager to TypeScript (#5766)
This commit is contained in:
parent
01578446fa
commit
da6e6c00e5
@ -13,32 +13,23 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
import {CDPSession} from './Connection';
|
||||||
|
|
||||||
// Used as a TypeDef
|
export class EmulationManager {
|
||||||
// eslint-disable-next-line no-unused-vars
|
_client: CDPSession;
|
||||||
const {CDPSession} = require('./Connection');
|
_emulatingMobile = false;
|
||||||
|
_hasTouch = false;
|
||||||
|
|
||||||
class EmulationManager {
|
constructor(client: CDPSession) {
|
||||||
/**
|
|
||||||
* @param {!CDPSession} client
|
|
||||||
*/
|
|
||||||
constructor(client) {
|
|
||||||
this._client = client;
|
this._client = client;
|
||||||
this._emulatingMobile = false;
|
|
||||||
this._hasTouch = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
async emulateViewport(viewport: Puppeteer.Viewport): Promise<boolean> {
|
||||||
* @param {!Puppeteer.Viewport} viewport
|
|
||||||
* @return {Promise<boolean>}
|
|
||||||
*/
|
|
||||||
async emulateViewport(viewport) {
|
|
||||||
const mobile = viewport.isMobile || false;
|
const mobile = viewport.isMobile || false;
|
||||||
const width = viewport.width;
|
const width = viewport.width;
|
||||||
const height = viewport.height;
|
const height = viewport.height;
|
||||||
const deviceScaleFactor = viewport.deviceScaleFactor || 1;
|
const deviceScaleFactor = viewport.deviceScaleFactor || 1;
|
||||||
/** @type {Protocol.Emulation.ScreenOrientation} */
|
const screenOrientation: Protocol.Emulation.ScreenOrientation = viewport.isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'};
|
||||||
const screenOrientation = viewport.isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'};
|
|
||||||
const hasTouch = viewport.hasTouch || false;
|
const hasTouch = viewport.hasTouch || false;
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@ -54,5 +45,3 @@ class EmulationManager {
|
|||||||
return reloadNeeded;
|
return reloadNeeded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {EmulationManager};
|
|
Loading…
Reference in New Issue
Block a user