electron 可以解析渲染 vue 等前端框架生成html

mainWindow.webContents.on('dom-ready', () => {

    // console.log(document.documentElement.outerHTML);

    // 执行JavaScript来获取HTML内容
    mainWindow.webContents.executeJavaScript(`
          // 获取HTML内容
          document.documentElement.outerHTML;
      `)
      .then(htmlContent => {
        // 打印HTML内容
        console.log(htmlContent);
        // 将HTML内容写入文件
        fs.writeFile('page.html', htmlContent, 'utf8', (err) => {
          if (err) {
            console.error('Error writing file:', err);
            return;
          }
          console.log('HTML content saved to page.html');
        });
      })
      .catch(error => {
        console.error('Error executing JavaScript:', error);
      });
  });
« Back to Home

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment