launcher: more wip allowRedirects
This commit is contained in:
parent
8f13d4af2e
commit
11c5abe4f3
@ -13,8 +13,6 @@ export default async (CDP, evaluate, { browserType, dataPath }) => {
|
||||
};
|
||||
}
|
||||
|
||||
await CDP.send('Page.enable');
|
||||
|
||||
const getDefaultPath = () => join(dataPath, 'v8Cache.json');
|
||||
const getScriptUrls = async (includePreload = true) => (await evaluate(`[...document.querySelectorAll('script[src]${includePreload ? ', link[as=script]' : ''}')].map(x => x.src ?? x.href).join(';')`)).split(';');
|
||||
|
||||
|
@ -202,7 +202,7 @@ const startBrowser = async (url, { allowHTTP = false, allowRedirects = 'same-ori
|
||||
const basePath = isAbsolute(url) ? url : join(ranJsDir, url);
|
||||
|
||||
const closeHandlers = [];
|
||||
if (openingLocal && browserType === 'firefox') closeHandlers.push(await LocalHTTP({ localUrl, url: basePath }));
|
||||
if (openingLocal && browserType === 'firefox') closeHandlers.push(await LocalHTTP({ url: localUrl, basePath }));
|
||||
|
||||
const Window = await (browserType === 'firefox' ? Firefox : Chromium)({
|
||||
dataPath,
|
||||
@ -214,8 +214,8 @@ const startBrowser = async (url, { allowHTTP = false, allowRedirects = 'same-ori
|
||||
extensions: ExtensionsAPI._extensions[browserType]
|
||||
}, {
|
||||
browserName: browserFriendlyName,
|
||||
url: openingLocal ? basePath : url,
|
||||
localUrl,
|
||||
url: openingLocal ? localUrl : url,
|
||||
basePath,
|
||||
openingLocal,
|
||||
closeHandlers,
|
||||
browserType,
|
||||
|
@ -27,10 +27,10 @@ const acquireTarget = async (CDP, filter = () => true) => {
|
||||
})).sessionId;
|
||||
};
|
||||
|
||||
export default async (CDP, proc, injectionType = 'browser', { dataPath, browserName, browserType, openingLocal, localUrl, url, allowRedirects, closeHandlers }) => {
|
||||
export default async (CDP, proc, injectionType = 'browser', { dataPath, browserName, browserType, openingLocal, url, basePath, allowRedirects, closeHandlers }) => {
|
||||
let pageLoadCallback, pageLoadPromise = new Promise(res => pageLoadCallback = res);
|
||||
let frameLoadCallback = () => {}, onWindowMessage = () => {};
|
||||
CDP.onMessage(msg => {
|
||||
CDP.onMessage(async msg => {
|
||||
if (msg.method === 'Runtime.bindingCalled' && msg.params.name === '_gluonSend') onWindowMessage(JSON.parse(msg.params.payload));
|
||||
if (msg.method === 'Page.frameStoppedLoading') frameLoadCallback(msg.params);
|
||||
if (msg.method === 'Page.loadEventFired') pageLoadCallback();
|
||||
@ -45,13 +45,21 @@ export default async (CDP, proc, injectionType = 'browser', { dataPath, browserN
|
||||
if (allowRedirects === true) return;
|
||||
if (allowRedirects === 'same-origin' && new URL(newUrl).origin === new URL(url).origin) return;
|
||||
|
||||
console.log(url, new URL(url).origin);
|
||||
|
||||
CDP.sendMessage('Page.stopLoading', {}, sessionId);
|
||||
|
||||
if (msg.method === 'Page.frameNavigated') {
|
||||
CDP.sendMessage('Page.navigate', { url: 'about:blank' }, sessionId);
|
||||
// CDP.sendMessage('Page.navigate')
|
||||
|
||||
const history = await CDP.sendMessage('Page.getNavigationHistory', {}, sessionId);
|
||||
const oldUrl = history.entries[history.currentIndex - 1].url;
|
||||
|
||||
CDP.sendMessage('Page.navigate', {
|
||||
url: oldUrl,
|
||||
frameId: msg.params.frame.id
|
||||
}, sessionId);
|
||||
}
|
||||
// CDP.sendMessage('Page.navigate', { url: 'about:blank' }, sessionId);
|
||||
}
|
||||
});
|
||||
|
||||
@ -66,9 +74,10 @@ export default async (CDP, proc, injectionType = 'browser', { dataPath, browserN
|
||||
let sessionId;
|
||||
if (injectionType === 'browser') sessionId = await acquireTarget(CDP, target => target.url !== 'about:blank');
|
||||
|
||||
if (openingLocal && browserType === 'chromium') await LocalCDP(CDP, { sessionId, localUrl, url });
|
||||
if (openingLocal && browserType === 'chromium') await LocalCDP(CDP, { sessionId, url, basePath });
|
||||
|
||||
await CDP.sendMessage('Runtime.enable', {}, sessionId); // enable runtime API
|
||||
CDP.sendMessage('Page.enable', {}, sessionId); // enable page API
|
||||
|
||||
CDP.sendMessage('Runtime.addBinding', { // setup sending from window to Node via Binding
|
||||
name: '_gluonSend'
|
||||
|
@ -1,8 +1,8 @@
|
||||
import createLocalFulfill from './fulfill.js';
|
||||
import { log } from '../logger.js';
|
||||
|
||||
export default async (CDP, { sessionId, url: givenPath, localUrl }) => {
|
||||
const localFulfill = createLocalFulfill(givenPath);
|
||||
export default async (CDP, { sessionId, basePath, url }) => {
|
||||
const localFulfill = createLocalFulfill(basePath);
|
||||
|
||||
CDP.onMessage(async msg => {
|
||||
if (msg.method === 'Fetch.requestPaused') {
|
||||
@ -21,7 +21,7 @@ export default async (CDP, { sessionId, url: givenPath, localUrl }) => {
|
||||
|
||||
await CDP.sendMessage('Fetch.enable', {
|
||||
patterns: [ {
|
||||
urlPattern: `${localUrl}*`
|
||||
urlPattern: `${url}*`
|
||||
} ]
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,7 @@ const generatePath = (pathname, indexFile) => {
|
||||
|
||||
export default givenPath => {
|
||||
const basePath = extname(givenPath) ? dirname(givenPath) : givenPath;
|
||||
const indexFile = extname(givenPath) ? basename(givenPath) : 'index.html';
|
||||
const indexFile = extname(basePath) ? basename(basePath) : 'index.html';
|
||||
|
||||
return async url => {
|
||||
url = new URL(url);
|
||||
|
@ -2,12 +2,12 @@ import { createServer } from 'http';
|
||||
import createLocalFulfill from './fulfill.js';
|
||||
import { log } from '../logger.js';
|
||||
|
||||
export default async ({ url: givenPath, localUrl }) => {
|
||||
const localFulfill = createLocalFulfill(givenPath);
|
||||
export default async ({ basePath, url }) => {
|
||||
const localFulfill = createLocalFulfill(basePath);
|
||||
|
||||
const port = parseInt(localUrl.split(':').pop());
|
||||
const port = parseInt(url.split(':').pop());
|
||||
const server = createServer(async (req, res) => {
|
||||
const { status, body, headers } = await localFulfill(localUrl + decodeURI(req.url));
|
||||
const { status, body, headers } = await localFulfill(url + decodeURI(req.url));
|
||||
|
||||
res.writeHead(status, headers);
|
||||
res.end(body, 'utf8');
|
||||
|
Loading…
x
Reference in New Issue
Block a user