Class: Puppeteer

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer.rb,
lib/puppeteer.rb,
lib/puppeteer/env.rb,
lib/puppeteer/version.rb

Overview

Defined Under Namespace

Modules: ConcurrentRubyUtils, DebugPrint, DefineAsyncMethod, EventCallbackable, IfPresent, Launcher Classes: AriaQueryHandler, Browser, BrowserContext, BrowserFetcher, BrowserRunner, CDPSession, Connection, ConsoleMessage, CustomQueryHandler, DOMWorld, Device, Devices, Dialog, ElementHandle, EmulationManager, Env, ExceptionDetails, ExecutionContext, FileChooser, Frame, FrameManager, Geolocation, JSHandle, Keyboard, LifecycleWatcher, Mouse, NetworkManager, Page, QueryHandlerManager, RemoteObject, Request, Response, Target, TimeoutError, TimeoutSettings, TouchScreen, Viewport, WaitTask, WebSocket, WebSocketTransport

Constant Summary collapse

DEVICES =
Hash[
  [
    {
      name: 'Blackberry PlayBook',
      userAgent:
        'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+',
      viewport: {
        width: 600,
        height: 1024,
        deviceScaleFactor: 1,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Blackberry PlayBook landscape',
      userAgent:
        'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+',
      viewport: {
        width: 1024,
        height: 600,
        deviceScaleFactor: 1,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'BlackBerry Z30',
      userAgent:
        'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+',
      viewport: {
        width: 360,
        height: 640,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'BlackBerry Z30 landscape',
      userAgent:
        'Mozilla/5.0 (BB10; Touch) AppleWebKit/537.10+ (KHTML, like Gecko) Version/10.0.9.2372 Mobile Safari/537.10+',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Galaxy Note 3',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
      viewport: {
        width: 360,
        height: 640,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Galaxy Note 3 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Galaxy Note II',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
      viewport: {
        width: 360,
        height: 640,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Galaxy Note II landscape',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Galaxy S III',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
      viewport: {
        width: 360,
        height: 640,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Galaxy S III landscape',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Galaxy S5',
      userAgent:
        'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 360,
        height: 640,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Galaxy S5 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPad',
      userAgent:
        'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
      viewport: {
        width: 768,
        height: 1024,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPad landscape',
      userAgent:
        'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
      viewport: {
        width: 1024,
        height: 768,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPad Mini',
      userAgent:
        'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
      viewport: {
        width: 768,
        height: 1024,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPad Mini landscape',
      userAgent:
        'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
      viewport: {
        width: 1024,
        height: 768,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPad Pro',
      userAgent:
        'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
      viewport: {
        width: 1024,
        height: 1366,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPad Pro landscape',
      userAgent:
        'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1',
      viewport: {
        width: 1366,
        height: 1024,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 4',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
      viewport: {
        width: 320,
        height: 480,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 4 landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53',
      viewport: {
        width: 480,
        height: 320,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 5',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
      viewport: {
        width: 320,
        height: 568,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 5 landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
      viewport: {
        width: 568,
        height: 320,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 6',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 375,
        height: 667,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 6 landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 667,
        height: 375,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 6 Plus',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 414,
        height: 736,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 6 Plus landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 736,
        height: 414,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 7',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 375,
        height: 667,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 7 landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 667,
        height: 375,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 7 Plus',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 414,
        height: 736,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 7 Plus landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 736,
        height: 414,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 8',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 375,
        height: 667,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 8 landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 667,
        height: 375,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 8 Plus',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 414,
        height: 736,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 8 Plus landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 736,
        height: 414,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone SE',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
      viewport: {
        width: 320,
        height: 568,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone SE landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1',
      viewport: {
        width: 568,
        height: 320,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone X',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 375,
        height: 812,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone X landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
      viewport: {
        width: 812,
        height: 375,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone XR',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 414,
        height: 896,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone XR landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 12_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 896,
        height: 414,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 11',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 414,
        height: 828,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 11 landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 828,
        height: 414,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 11 Pro',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 375,
        height: 812,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 11 Pro landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 812,
        height: 375,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'iPhone 11 Pro Max',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 414,
        height: 896,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'iPhone 11 Pro Max landscape',
      userAgent:
        'Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Mobile/15E148 Safari/604.1',
      viewport: {
        width: 896,
        height: 414,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'JioPhone 2',
      userAgent:
        'Mozilla/5.0 (Mobile; LYF/F300B/LYF-F300B-001-01-15-130718-i;Android; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.5',
      viewport: {
        width: 240,
        height: 320,
        deviceScaleFactor: 1,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'JioPhone 2 landscape',
      userAgent:
        'Mozilla/5.0 (Mobile; LYF/F300B/LYF-F300B-001-01-15-130718-i;Android; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.5',
      viewport: {
        width: 320,
        height: 240,
        deviceScaleFactor: 1,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Kindle Fire HDX',
      userAgent:
        'Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true',
      viewport: {
        width: 800,
        height: 1280,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Kindle Fire HDX landscape',
      userAgent:
        'Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true',
      viewport: {
        width: 1280,
        height: 800,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'LG Optimus L70',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 384,
        height: 640,
        deviceScaleFactor: 1.25,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'LG Optimus L70 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 640,
        height: 384,
        deviceScaleFactor: 1.25,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Microsoft Lumia 550',
      userAgent:
        'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 550) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Microsoft Lumia 950',
      userAgent:
        'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
      viewport: {
        width: 360,
        height: 640,
        deviceScaleFactor: 4,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Microsoft Lumia 950 landscape',
      userAgent:
        'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 4,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nexus 10',
      userAgent:
        'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
      viewport: {
        width: 800,
        height: 1280,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nexus 10 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 10 Build/MOB31T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
      viewport: {
        width: 1280,
        height: 800,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nexus 4',
      userAgent:
        'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 384,
        height: 640,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nexus 4 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 640,
        height: 384,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nexus 5',
      userAgent:
        'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 360,
        height: 640,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nexus 5 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 640,
        height: 360,
        deviceScaleFactor: 3,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nexus 5X',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 412,
        height: 732,
        deviceScaleFactor: 2.625,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nexus 5X landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 5X Build/OPR4.170623.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 732,
        height: 412,
        deviceScaleFactor: 2.625,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nexus 6',
      userAgent:
        'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 412,
        height: 732,
        deviceScaleFactor: 3.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nexus 6 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 7.1.1; Nexus 6 Build/N6F26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 732,
        height: 412,
        deviceScaleFactor: 3.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nexus 6P',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 412,
        height: 732,
        deviceScaleFactor: 3.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nexus 6P landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0.0; Nexus 6P Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 732,
        height: 412,
        deviceScaleFactor: 3.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nexus 7',
      userAgent:
        'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
      viewport: {
        width: 600,
        height: 960,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nexus 7 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 7 Build/MOB30X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Safari/537.36',
      viewport: {
        width: 960,
        height: 600,
        deviceScaleFactor: 2,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nokia Lumia 520',
      userAgent:
        'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)',
      viewport: {
        width: 320,
        height: 533,
        deviceScaleFactor: 1.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nokia Lumia 520 landscape',
      userAgent:
        'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)',
      viewport: {
        width: 533,
        height: 320,
        deviceScaleFactor: 1.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Nokia N9',
      userAgent:
        'Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13',
      viewport: {
        width: 480,
        height: 854,
        deviceScaleFactor: 1,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Nokia N9 landscape',
      userAgent:
        'Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13',
      viewport: {
        width: 854,
        height: 480,
        deviceScaleFactor: 1,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Pixel 2',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 411,
        height: 731,
        deviceScaleFactor: 2.625,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Pixel 2 landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 731,
        height: 411,
        deviceScaleFactor: 2.625,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
    {
      name: 'Pixel 2 XL',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 411,
        height: 823,
        deviceScaleFactor: 3.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: false,
      },
    },
    {
      name: 'Pixel 2 XL landscape',
      userAgent:
        'Mozilla/5.0 (Linux; Android 8.0.0; Pixel 2 XL Build/OPD1.170816.004) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3765.0 Mobile Safari/537.36',
      viewport: {
        width: 823,
        height: 411,
        deviceScaleFactor: 3.5,
        isMobile: true,
        hasTouch: true,
        isLandscape: true,
      },
    },
  ].map do |json|
    [
      json[:name],
      Puppeteer::Device.new(
        name: json[:name],
        user_agent: json[:userAgent],
        viewport: Puppeteer::Viewport.new(
          width: json[:viewport][:width],
          height: json[:viewport][:height],
          device_scale_factor: json[:viewport][:deviceScaleFactor],
          is_mobile: json[:viewport][:isMobile],
          has_touch: json[:viewport][:hasTouch],
          is_landscape: json[:viewport][:isLandscape],
        ),
      ),
    ]
  end
]
VERSION =
'0.30.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_root:, preferred_revision:, is_puppeteer_core:) ⇒ Puppeteer

Returns a new instance of Puppeteer.

Parameters:

  • project_root (String)
  • prefereed_revision (String)
  • is_puppeteer_core (String)


80
81
82
83
84
# File 'lib/puppeteer.rb', line 80

def initialize(project_root:, preferred_revision:, is_puppeteer_core:)
  @project_root = project_root
  @preferred_revision = preferred_revision
  @is_puppeteer_core = is_puppeteer_core
end

Class Method Details

.envObject



20
21
22
# File 'lib/puppeteer/env.rb', line 20

def self.env
  Puppeteer::Env.new
end

.method_missing(method, *args, **kwargs, &block) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/puppeteer.rb', line 63

def self.method_missing(method, *args, **kwargs, &block)
  @puppeteer ||= Puppeteer.new(
    project_root: __dir__,
    preferred_revision: '706915',
    is_puppeteer_core: true,
  )

  if kwargs.empty? # for Ruby < 2.7
    @puppeteer.public_send(method, *args, &block)
  else
    @puppeteer.public_send(method, *args, **kwargs, &block)
  end
end

Instance Method Details

#connect(browser_ws_endpoint: nil, browser_url: nil, transport: nil, ignore_https_errors: nil, default_viewport: nil, slow_mo: nil) ⇒ Puppeteer::Browser

Parameters:

  • browser_ws_endpoint (String) (defaults to: nil)
  • browser_url (String) (defaults to: nil)
  • transport (Puppeteer::WebSocketTransport) (defaults to: nil)
  • ignore_https_errors (Boolean) (defaults to: nil)
  • default_viewport (Puppeteer::Viewport|nil) (defaults to: nil)
  • slow_mo (Integer) (defaults to: nil)

Returns:



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/puppeteer.rb', line 162

def connect(
  browser_ws_endpoint: nil,
  browser_url: nil,
  transport: nil,
  ignore_https_errors: nil,
  default_viewport: nil,
  slow_mo: nil
)
  options = {
    browser_ws_endpoint: browser_ws_endpoint,
    browser_url: browser_url,
    transport: transport,
    ignore_https_errors: ignore_https_errors,
    default_viewport: default_viewport,
    slow_mo: slow_mo,
  }.compact
  browser = launcher.connect(options)
  if block_given?
    begin
      yield(browser)
    ensure
      browser.disconnect
    end
  else
    browser
  end
end

#createBrowserFetcher(options = {}) ⇒ !BrowserFetcher

Parameters:

Returns:



236
237
238
# File 'lib/puppeteer.rb', line 236

def createBrowserFetcher(options = {})
  BrowserFetcher.new(@project_root, options)
end

#default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil) ⇒ Array<String>

Parameters:

  • args (Array<String>) (defaults to: nil)
  • user_data_dir (String) (defaults to: nil)
  • devtools (Boolean) (defaults to: nil)
  • headless (Boolean) (defaults to: nil)

Returns:

  • (Array<String>)


224
225
226
227
228
229
230
231
232
# File 'lib/puppeteer.rb', line 224

def default_args(args: nil, user_data_dir: nil, devtools: nil, headless: nil)
  options = {
    args: args,
    user_data_dir: user_data_dir,
    devtools: devtools,
    headless: headless,
  }.compact
  launcher.default_args(options)
end

#devicesPuppeteer::Devices

Returns:



210
211
212
# File 'lib/puppeteer.rb', line 210

def devices
  Puppeteer::Devices
end

#executable_pathString

Returns:

  • (String)


191
192
193
# File 'lib/puppeteer.rb', line 191

def executable_path
  launcher.executable_path
end

#launch(product: nil, executable_path: nil, ignore_default_args: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil, timeout: nil, dumpio: nil, env: nil, pipe: nil, args: nil, user_data_dir: nil, devtools: nil, headless: nil, ignore_https_errors: nil, default_viewport: nil, slow_mo: nil) ⇒ Puppeteer::Browser

Parameters:

  • product (String) (defaults to: nil)
  • executable_path (String) (defaults to: nil)
  • ignore_default_args (Array<String>|nil) (defaults to: nil)
  • handle_SIGINT (Boolean) (defaults to: nil)
  • handle_SIGTERM (Boolean) (defaults to: nil)
  • handle_SIGHUP (Boolean) (defaults to: nil)
  • timeout (Integer) (defaults to: nil)
  • dumpio (Boolean) (defaults to: nil)
  • env (Hash) (defaults to: nil)
  • pipe (Boolean) (defaults to: nil)
  • args (Array<String>) (defaults to: nil)
  • user_data_dir (String) (defaults to: nil)
  • devtools (Boolean) (defaults to: nil)
  • headless (Boolean) (defaults to: nil)
  • ignore_https_errors (Boolean) (defaults to: nil)
  • default_viewport (Puppeteer::Viewport|nil) (defaults to: nil)
  • slow_mo (Integer) (defaults to: nil)

Returns:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/puppeteer.rb', line 104

def launch(
  product: nil,
  executable_path: nil,
  ignore_default_args: nil,
  handle_SIGINT: nil,
  handle_SIGTERM: nil,
  handle_SIGHUP: nil,
  timeout: nil,
  dumpio: nil,
  env: nil,
  pipe: nil,
  args: nil,
  user_data_dir: nil,
  devtools: nil,
  headless: nil,
  ignore_https_errors: nil,
  default_viewport: nil,
  slow_mo: nil
)
  options = {
    executable_path: executable_path,
    ignore_default_args: ignore_default_args,
    handle_SIGINT: handle_SIGINT,
    handle_SIGTERM: handle_SIGTERM,
    handle_SIGHUP: handle_SIGHUP,
    timeout: timeout,
    dumpio: dumpio,
    env: env,
    pipe: pipe,
    args: args,
    user_data_dir: user_data_dir,
    devtools: devtools,
    headless: headless,
    ignore_https_errors: ignore_https_errors,
    default_viewport: default_viewport,
    slow_mo: slow_mo,
  }

  @product_name ||= product
  browser = launcher.launch(options)
  if block_given?
    begin
      yield(browser)
    ensure
      browser.close
    end
  else
    browser
  end
end

#productString

Returns:

  • (String)


205
206
207
# File 'lib/puppeteer.rb', line 205

def product
  launcher.product
end