Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ RUN apt-get update \
libx11-6 \
libxext6 \
libxkbcommon0 \
unzip \
x11-utils \
xdg-utils \
zlib1g \
&& rm -rf /var/lib/apt/lists/*

# Set up a working directory
ENV HOME /opt/phantomas
ENV HOME=/opt/phantomas
WORKDIR $HOME
RUN chown -R nobody:nogroup .

# Run everything after as non-privileged user.
USER nobody

ENV DOCKERIZED yes
ENV DOCKERIZED=yes

# Install dependencies
COPY package.json .
Expand All @@ -46,13 +47,13 @@ RUN npm ci
RUN echo "Chrome found in: " $(find . -wholename '*chrome-linux64/chrome') && \
ln -s $(find . -wholename '*chrome-linux64/chrome') .

ENV PATH ${PATH}":/opt/phantomas"
ENV PATH=${PATH}":/opt/phantomas"

RUN ldd chrome && \
chrome --version

ARG GITHUB_SHA="dev"
ENV COMMIT_SHA ${GITHUB_SHA}
ENV COMMIT_SHA=${GITHUB_SHA}

# label the image with branch name and commit hash
LABEL maintainer="maciej.brencz@gmail.com"
Expand Down
35 changes: 18 additions & 17 deletions extensions/devices/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
"use strict";

module.exports = function (phantomas) {
const puppeteer = require("puppeteer"),
devices = puppeteer.KnownDevices,
// @see https://github.com/puppeteer/puppeteer/blob/main/packages/puppeteer-core/src/common/Device.ts
availableDevices = {
phone: "Galaxy S5", // 360x640
"phone-landscape": "Galaxy S5 landscape", // 640x360
tablet: "Kindle Fire HDX", // 800x1200
"tablet-landscape": "Kindle Fire HDX landscape", // 1280x800
};
// @see https://github.com/puppeteer/puppeteer/blob/main/packages/puppeteer-core/src/common/Device.ts
const availableDevices = {
phone: "Galaxy S5", // 360x640
"phone-landscape": "Galaxy S5 landscape", // 640x360
tablet: "Kindle Fire HDX", // 800x1200
"tablet-landscape": "Kindle Fire HDX landscape", // 1280x800
};

let device;

Expand All @@ -36,16 +34,19 @@ module.exports = function (phantomas) {
// apply the profile
const profileName = availableDevices[device];

phantomas.log(
'Devices: %s provided - using "%s" profile: %j',
device,
profileName,
devices[profileName]
);

phantomas.on("init", async (page) => {
const { KnownDevices } = await import("puppeteer");
const deviceProfile = KnownDevices[profileName];

phantomas.log(
'Devices: %s provided - using "%s" profile: %j',
device,
profileName,
deviceProfile
);

// @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageemulateoptions
await page.emulate(devices[profileName]);
await page.emulate(deviceProfile);
phantomas.log("page.emulate() called");
});
};
6 changes: 3 additions & 3 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
/**
* Expose puppeteer API and events emitter object for lib/index.js
*/
const debug = require("debug")("phantomas:browser"),
puppeteer = require("puppeteer");
const debug = require("debug")("phantomas:browser");

function Browser() {
this.browser = null;
Expand Down Expand Up @@ -77,6 +76,7 @@ Browser.prototype.init = async (phantomasOptions) => {

try {
// https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.browserlaunchargumentoptions.md
const { default: puppeteer } = await import("puppeteer");
this.browser = await puppeteer.launch(options);
this.page = await this.browser.newPage();
} catch (ex) /* istanbul ignore next */ {
Expand Down Expand Up @@ -346,7 +346,7 @@ Browser.prototype.close = async () => {

try {
// The page is closed, let's close the browser
if (this.browser && this.browser.isConnected()) await this.browser.close();
if (this.browser && this.browser.connected) await this.browser.close();
} catch (ex) /* istanbul ignore next */ {
debug("An exception was raised while closing the browser: " + ex);
debug(ex);
Expand Down
5 changes: 0 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Browser = require("./browser"),
EventEmitter = require("./AwaitEventEmitter"),
debug = require("debug")("phantomas:core"),
loader = require("./loader"),
puppeteer = require("puppeteer"),
path = require("path"),
Results = require("../core/results"),
VERSION = require("./../package").version;
Expand All @@ -27,10 +26,6 @@ function phantomas(url, opts) {
debug("OS: %s %s", process.platform, process.arch);
debug("Node.js: %s", process.version);
debug("phantomas: %s", VERSION);
debug(
"Puppeteer: preferred revision r%s",
puppeteer.default._preferredRevision
);
debug("URL: <%s>", url);

// options handling
Expand Down
Loading
Loading