wkProvisionalPage.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.WKProvisionalPage = void 0;
  6. var _eventsHelper = require("../../utils/eventsHelper");
  7. var _utils = require("../../utils");
  8. /**
  9. * Copyright (c) Microsoft Corporation.
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. */
  23. class WKProvisionalPage {
  24. constructor(session, page) {
  25. this._session = void 0;
  26. this._wkPage = void 0;
  27. this._sessionListeners = [];
  28. this._mainFrameId = null;
  29. this.initializationPromise = void 0;
  30. this._session = session;
  31. this._wkPage = page;
  32. const overrideFrameId = handler => {
  33. return payload => {
  34. // Pretend that the events happened in the same process.
  35. if (payload.frameId) payload.frameId = this._wkPage._page._frameManager.mainFrame()._id;
  36. handler(payload);
  37. };
  38. };
  39. const wkPage = this._wkPage;
  40. this._sessionListeners = [_eventsHelper.eventsHelper.addEventListener(session, 'Network.requestWillBeSent', overrideFrameId(e => wkPage._onRequestWillBeSent(session, e))), _eventsHelper.eventsHelper.addEventListener(session, 'Network.requestIntercepted', overrideFrameId(e => wkPage._onRequestIntercepted(session, e))), _eventsHelper.eventsHelper.addEventListener(session, 'Network.responseReceived', overrideFrameId(e => wkPage._onResponseReceived(session, e))), _eventsHelper.eventsHelper.addEventListener(session, 'Network.loadingFinished', overrideFrameId(e => wkPage._onLoadingFinished(e))), _eventsHelper.eventsHelper.addEventListener(session, 'Network.loadingFailed', overrideFrameId(e => wkPage._onLoadingFailed(session, e)))];
  41. this.initializationPromise = this._wkPage._initializeSession(session, true, ({
  42. frameTree
  43. }) => this._handleFrameTree(frameTree));
  44. }
  45. dispose() {
  46. _eventsHelper.eventsHelper.removeEventListeners(this._sessionListeners);
  47. }
  48. commit() {
  49. (0, _utils.assert)(this._mainFrameId);
  50. this._wkPage._onFrameAttached(this._mainFrameId, null);
  51. }
  52. _handleFrameTree(frameTree) {
  53. (0, _utils.assert)(!frameTree.frame.parentId);
  54. this._mainFrameId = frameTree.frame.id;
  55. }
  56. }
  57. exports.WKProvisionalPage = WKProvisionalPage;