UNPKG

@copperjs/copper

Version:
41 lines 1.88 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.navigation = void 0; const errors_1 = require("../../../common/errors"); const navigation = (app, opts, done) => { app.post('/url', async (req) => { const { url, waitUntil } = req.body; if (!url) { throw new errors_1.WebdriverError('Missing URL'); } await req.puppeteer.page.goto(url, { waitUntil: waitUntil !== null && waitUntil !== void 0 ? waitUntil : 'networkidle0' }); return { status: 0, value: null, state: 'success' }; }); app.get('/url', async (req) => { const value = await req.puppeteer.page.url(); return { status: 0, value, state: 'success' }; }); app.post('/back', async (req) => { const { waitUntil } = req.body; await req.puppeteer.page.goBack({ waitUntil: waitUntil !== null && waitUntil !== void 0 ? waitUntil : 'networkidle0' }); return { status: 0, value: null, state: 'success' }; }); app.post('/forward', async (req) => { const { waitUntil } = req.body; await req.puppeteer.page.goForward({ waitUntil: waitUntil !== null && waitUntil !== void 0 ? waitUntil : 'networkidle0' }); return { status: 0, value: null, state: 'success' }; }); app.post('/refresh', async (req) => { const { waitUntil } = req.body; await req.puppeteer.page.reload({ waitUntil: waitUntil !== null && waitUntil !== void 0 ? waitUntil : 'networkidle0' }); return { status: 0, value: null, state: 'success' }; }); app.get('/title', async (req) => { var _a; const value = await ((_a = req.puppeteer) === null || _a === void 0 ? void 0 : _a.page.title()); return { status: 0, value, state: 'success' }; }); done(); }; exports.navigation = navigation; //# sourceMappingURL=navigation.js.map