Skip to content

Commit

Permalink
use local browser instead of installed chromium (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukwants committed Oct 6, 2023
1 parent 4f62a4b commit ebf4fbf
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 645 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Atiro 支持的评测辅助程序有 `checker`、`interactor`、`solver`、`gene

### OJ Tools

**需要使用 `atiro config browser.path --set /path/to/browser` 指定一个基于 Chromium 的浏览器路径(如 Chrome 或 Edge),可以通过 `chrome://version``edge://version` 获取可执行文件路径。**


```bash
$ atiro <oj> login|i | logout|o | get|g <id> [file] | submit|s [file] [id]
```
Expand Down Expand Up @@ -204,6 +207,7 @@ $ atiro c judge.time --unset # 清除默认时间限制设置
- `judge.solv`,默认 `solver`,即 `judge` 命令的 `solv` 选项。
- `judge.make`,默认 `generator`,即 `judge` 命令的 `make` 选项。
- `update.type`,更新版本自动检测模式。
- `browser.path`,浏览器路径,OJ Tools 必需选项。

### Update

Expand Down
3 changes: 3 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const config = data('config', {
},
update: {
type: 'notice'
},
browser: {
path: null
}
}, true);

Expand Down
2 changes: 1 addition & 1 deletion lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = (cate, defaults, message) => {
}
fs.writeFileSync(filePath, JSON.stringify(data));
if (noMessage != undefined ? !noMessage : message) {
console.log(chalk.green('[Success]'), 'Set the successfully.');
console.log(chalk.green('[Success]'), 'Set successfully.');
}
} catch (error) {
console.log(chalk.gray('[Mysterious Error]'), 'Failed on setting.');
Expand Down
11 changes: 9 additions & 2 deletions lib/webtool.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
const puppeteer = require('puppeteer');
const puppeteer = require('puppeteer-core');
const chalk = require('chalk');
const { exit } = require('./utils.js');

const config = require('./config.js');
const produced = require('./produced.js');

async function open(website, options) {
const browser = await puppeteer.launch({ headless: 'new', defaultViewport: null, ...options });
if (!config.getValue('browser', 'path')) {
console.log(chalk.blue('[Notice]'), `Please specify the browser path first. Run \`${require('../package.json').name} config browser.path --set /path/to/browser\`!`);
exit();
}
const browser = await puppeteer.launch({ executablePath: config.getValue('browser', 'path'), headless: 'new', defaultViewport: null, ...options });
const page = (await browser.pages())[0];
const cookies = produced.getValue('cookies', website);
for (let cookie of cookies) {
Expand Down

0 comments on commit ebf4fbf

Please sign in to comment.