I tried some changes and have the feeling at least came further, without being a bit smarter.
import { App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, renderResults, Setting, } from 'obsidian';
const puppeteer = require('puppeteer').default;
interface HtmlToPDFSettings {
mySetting: string;
}
const DEFAULT_SETTINGS: HtmlToPDFSettings = {
mySetting: 'default'
}
export default class HtmlToPDF extends Plugin {
settings: HtmlToPDFSettings;
async onload() {
await this.loadSettings();
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon('dice', 'HtmlToPDF2', (evt: MouseEvent) => {
// Called when the user clicks the icon.
new AskForUrl(this.app, (result) => {
new Notice("Fesnter Offen "+result);
async function scrapePage(url){
const browser = puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto(result);
await page.waitFor(10000);
await browser.close();
new Notice("Brwoser"+result);
}
scrapePage(result);
}).open();
//new Notice("Hey Hey");
});
I have randomly tried things which i gather in my google hunt.
{
"compilerOptions": {
"baseUrl": ".",
"inlineSourceMap": true,
"inlineSources": true,
"module": "ES2020",
"target": "ES6",
"allowJs": true,
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"allowSyntheticDefaultImports": true,
"lib": [
"DOM",
"ES5",
"ES6",
"ES7",
"esnext",
"ES2020",
]
},
"include": [
"**/*.ts"
],
}
I added "type": "module" in to package.json.
Now i get this as Error:
main.ts:30 Uncaught (in promise) TypeError: Cannot read property 'launch' of undefined
at scrapePage (eval at <anonymous> (app.js:1), <anonymous>:22545:37)
at AskForUrl.eval [as onSubmit] (eval at <anonymous> (app.js:1), <anonymous>:22552:9)
at eval (eval at <anonymous> (app.js:1), <anonymous>:22627:12)
at HTMLButtonElement.<anonymous> (app.js:1)