UNPKG

ice.fo.utils

Version:

36 lines (32 loc) 901 B
export default async function capturePageScreenshot ({ $axios }, options = { url: '', selector: '' }) { options = Object.assign({ mode: 'base64', windowWidth: 1366, imageWidth: options.windowWidth || 1366, imageHeight: 768, }, options) options.selector = options.selector && encodeURIComponent(options.selector) const res = await $axios.request({ url: '/api/ice/take_screenshot', params: { url: options.url, width: options.imageWidth, height: options.imageHeight, }, responseType: 'blob', }) switch (options.mode) { case 'blob': return res case 'base64': default: return new Promise((resolve) => { const reader = new window.FileReader() reader.readAsDataURL(res.data) reader.onload = function () { const base64 = reader.result resolve(base64) } }) } }