Spaces:
Paused
Paused
and
commited on
Commit
·
495f8f5
1
Parent(s):
9609abc
- index.mjs +6 -1
- test_evaluate.mjs +37 -13
index.mjs
CHANGED
|
@@ -73,8 +73,12 @@ async function text_from_url(url, cookie) {
|
|
| 73 |
async function screenshot(url, cookie, js_enabled) {
|
| 74 |
let { browser, context } = globalThis.state;
|
| 75 |
if (!browser) {
|
|
|
|
| 76 |
await locks.request('playwright_browser', async lock => {
|
| 77 |
-
browser = globalThis.state.browser = await chromium.launch(
|
|
|
|
|
|
|
|
|
|
| 78 |
context = globalThis.state.context = await browser.newContext({
|
| 79 |
javaScriptEnabled: js_enabled
|
| 80 |
}/*devices['iPhone 11']*/);
|
|
@@ -114,6 +118,7 @@ async function screenshot(url, cookie, js_enabled) {
|
|
| 114 |
async function evaluate(url, code) {
|
| 115 |
let { browser, context } = globalThis.state;
|
| 116 |
if (!browser) {
|
|
|
|
| 117 |
await locks.request('playwright_browser', async lock => {
|
| 118 |
browser = globalThis.state.browser = await chromium.launch();
|
| 119 |
context = globalThis.state.context = await browser.newContext({
|
|
|
|
| 73 |
async function screenshot(url, cookie, js_enabled) {
|
| 74 |
let { browser, context } = globalThis.state;
|
| 75 |
if (!browser) {
|
| 76 |
+
console.log('launch browser');
|
| 77 |
await locks.request('playwright_browser', async lock => {
|
| 78 |
+
browser = globalThis.state.browser = await chromium.launch({
|
| 79 |
+
args: ['--disable-web-security'] //https://github.com/microsoft/playwright/issues/17631
|
| 80 |
+
bypassCSP: true,
|
| 81 |
+
});
|
| 82 |
context = globalThis.state.context = await browser.newContext({
|
| 83 |
javaScriptEnabled: js_enabled
|
| 84 |
}/*devices['iPhone 11']*/);
|
|
|
|
| 118 |
async function evaluate(url, code) {
|
| 119 |
let { browser, context } = globalThis.state;
|
| 120 |
if (!browser) {
|
| 121 |
+
console.log('launch browser');
|
| 122 |
await locks.request('playwright_browser', async lock => {
|
| 123 |
browser = globalThis.state.browser = await chromium.launch();
|
| 124 |
context = globalThis.state.context = await browser.newContext({
|
test_evaluate.mjs
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
let res = await fetch('https://gowah44030-playwright.hf.space/evaluate', {
|
| 2 |
method: "POST",
|
| 3 |
body: JSON.stringify({
|
| 4 |
-
url: 'https://
|
| 5 |
code: `
|
| 6 |
(async function(){
|
| 7 |
return await new Promise(async (resolve)=>{
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
//ws.on('message', function message(_data) { console.log(_data);});
|
| 21 |
});
|
| 22 |
})()
|
| 23 |
`,
|
|
|
|
| 1 |
+
// let res = await fetch('https://gowah44030-playwright.hf.space/evaluate', {
|
| 2 |
+
// method: "POST",
|
| 3 |
+
// body: JSON.stringify({
|
| 4 |
+
// url: 'https://chat.lmsys.org/assets/index-c347e3dc.js',
|
| 5 |
+
// code: `
|
| 6 |
+
// (async function(){
|
| 7 |
+
// return await new Promise(async (resolve)=>{
|
| 8 |
+
|
| 9 |
+
// try {
|
| 10 |
+
// //resolve(await fetch('https://chat.lmsys.org').then(res=>res.text()));
|
| 11 |
+
// } catch (e) { resolve(e);}
|
| 12 |
+
// //return;
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
// const ws = new WebSocket('wss://chat.lmsys.org/queue/join');
|
| 16 |
+
// ws.addEventListener('error', (e) => { resolve('error');});
|
| 17 |
+
// ws.addEventListener('open', function open() { resolve('open');});
|
| 18 |
+
// ws.addEventListener('close', () => { resolve('A') });
|
| 19 |
+
|
| 20 |
+
// //ws.on('message', function message(_data) { console.log(_data);});
|
| 21 |
+
// });
|
| 22 |
+
// })()
|
| 23 |
+
// `,
|
| 24 |
+
// })
|
| 25 |
+
// }).then(res=>res.text());
|
| 26 |
+
|
| 27 |
let res = await fetch('https://gowah44030-playwright.hf.space/evaluate', {
|
| 28 |
method: "POST",
|
| 29 |
body: JSON.stringify({
|
| 30 |
+
url: 'https://www.investing.com',
|
| 31 |
code: `
|
| 32 |
(async function(){
|
| 33 |
return await new Promise(async (resolve)=>{
|
| 34 |
|
| 35 |
+
try {
|
| 36 |
+
resolve(
|
| 37 |
+
await fetch('https://api.investing.com/api/financialdata/8849/historical/chart/?interval=PT1M&pointscount=60')
|
| 38 |
+
//await fetch('https://www.investing.com')
|
| 39 |
+
.then(res=>{
|
| 40 |
+
return res.text();
|
| 41 |
+
})
|
| 42 |
+
);
|
| 43 |
+
} catch (e) { resolve(e);}
|
| 44 |
+
|
|
|
|
|
|
|
| 45 |
});
|
| 46 |
})()
|
| 47 |
`,
|