Skip to content

Simulator options ​

createSimulator(options) returns an ApkSimulator. Every option is optional except the render target.

Options ​

OptionTypeDefaultDescription
elementstring | ElementnullRender target. A CSS selector or a DOM node; a canvas is created inside it.
canvasHTMLCanvasElementnullExisting canvas. Takes precedence over element.
device.widthnumber360Logical width in pixels
device.heightnumber640Logical height in pixels
device.dprnumberwindow.devicePixelRatio capped at 2Device pixel ratio
device.stylestring'material'Theme style
device.maxApkSizenumber50 * 1024 * 1024APK size limit in bytes
onLog(entry) => voidnullLog callback, receives { level, tag, message }
onFinished() => voidnullFired when the activity finishes
onError(error) => voidnullFired on load or start failure

Example ​

js
import { createSimulator } from 'https://caofangkuai.github.io/apk.js/dist/apk.min.js';

const sim = createSimulator({
  element: '#screen',
  device: { width: 390, height: 844, dpr: 2 },
  onLog: ({ level, tag, message }) => console.log(level, tag, message),
});

Defaults ​

js
const DEFAULT_DEVICE = {
  width: 360,
  height: 640,
  dpr: undefined,
  style: 'material',
  maxApkSize: 50 * 1024 * 1024,
};

Released under the MIT License.