dialog.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Dialog = void 0;
  6. var _utils = require("../utils");
  7. var _instrumentation = require("./instrumentation");
  8. /**
  9. * Copyright 2017 Google Inc. All rights reserved.
  10. * Modifications copyright (c) Microsoft Corporation.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. class Dialog extends _instrumentation.SdkObject {
  25. constructor(page, type, message, onHandle, defaultValue) {
  26. super(page, 'dialog');
  27. this._page = void 0;
  28. this._type = void 0;
  29. this._message = void 0;
  30. this._onHandle = void 0;
  31. this._handled = false;
  32. this._defaultValue = void 0;
  33. this._page = page;
  34. this._type = type;
  35. this._message = message;
  36. this._onHandle = onHandle;
  37. this._defaultValue = defaultValue || '';
  38. this._page._frameManager.dialogDidOpen(this);
  39. }
  40. page() {
  41. return this._page;
  42. }
  43. type() {
  44. return this._type;
  45. }
  46. message() {
  47. return this._message;
  48. }
  49. defaultValue() {
  50. return this._defaultValue;
  51. }
  52. async accept(promptText) {
  53. (0, _utils.assert)(!this._handled, 'Cannot accept dialog which is already handled!');
  54. this._handled = true;
  55. this._page._frameManager.dialogWillClose(this);
  56. await this._onHandle(true, promptText);
  57. }
  58. async dismiss() {
  59. (0, _utils.assert)(!this._handled, 'Cannot dismiss dialog which is already handled!');
  60. this._handled = true;
  61. this._page._frameManager.dialogWillClose(this);
  62. await this._onHandle(false);
  63. }
  64. async close() {
  65. if (this._type === 'beforeunload') await this.accept();else await this.dismiss();
  66. }
  67. }
  68. exports.Dialog = Dialog;