install.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. var install_exports = {};
  30. __export(install_exports, {
  31. default: () => install_default
  32. });
  33. module.exports = __toCommonJS(install_exports);
  34. var import_child_process = require("child_process");
  35. var import_path = __toESM(require("path"));
  36. var import_bundle = require("../../sdk/bundle");
  37. var import_tool = require("./tool");
  38. const install = (0, import_tool.defineTool)({
  39. capability: "core-install",
  40. schema: {
  41. name: "browser_install",
  42. title: "Install the browser specified in the config",
  43. description: "Install the browser specified in the config. Call this if you get an error about the browser not being installed.",
  44. inputSchema: import_bundle.z.object({}),
  45. type: "action"
  46. },
  47. handle: async (context, params, response) => {
  48. const channel = context.config.browser?.launchOptions?.channel ?? context.config.browser?.browserName ?? "chrome";
  49. const cliPath = import_path.default.join(require.resolve("playwright/package.json"), "../cli.js");
  50. const child = (0, import_child_process.fork)(cliPath, ["install", channel], {
  51. stdio: "pipe"
  52. });
  53. const output = [];
  54. child.stdout?.on("data", (data) => output.push(data.toString()));
  55. child.stderr?.on("data", (data) => output.push(data.toString()));
  56. await new Promise((resolve, reject) => {
  57. child.on("close", (code) => {
  58. if (code === 0)
  59. resolve();
  60. else
  61. reject(new Error(`Failed to install browser: ${output.join("")}`));
  62. });
  63. });
  64. response.setIncludeTabs();
  65. }
  66. });
  67. var install_default = [
  68. install
  69. ];