MCPcopy Create free account
hub / github.com/HtmlUnit/htmlunit / initialize

Method initialize

src/main/java/org/htmlunit/html/HtmlPage.java:243–341  ·  view source on GitHub ↗

Initialize this page. @throws IOException if an IO problem occurs @throws FailingHttpStatusCodeException if the server returns a failing status code AND the property org.htmlunit.WebClientOptions#setThrowExceptionOnFailingStatusCode(boolean) is set to true.

()

Source from the content-addressed store, hash-verified

241 * to true.
242 */
243 @Override
244 public void initialize() throws IOException, FailingHttpStatusCodeException {
245 final WebWindow enclosingWindow = getEnclosingWindow();
246 final boolean isAboutBlank = getUrl() == UrlUtils.URL_ABOUT_BLANK;
247 if (isAboutBlank) {
248 // a frame contains first a faked "about:blank" before its real content specified by src gets loaded
249 if (enclosingWindow instanceof FrameWindow window
250 && !window.getFrameElement().isContentLoaded()) {
251 return;
252 }
253
254 // save the URL that should be used to resolve relative URLs in this page
255 if (enclosingWindow instanceof TopLevelWindow topWindow) {
256 final WebWindow openerWindow = topWindow.getOpener();
257 if (openerWindow != null && openerWindow.getEnclosedPage() != null) {
258 baseUrl_ = openerWindow.getEnclosedPage().getWebResponse().getWebRequest().getUrl();
259 }
260 }
261 }
262
263 if (!isAboutBlank) {
264 setReadyState(READY_STATE_INTERACTIVE);
265 getDocumentElement().setReadyState(READY_STATE_INTERACTIVE);
266 executeEventHandlersIfNeeded(Event.TYPE_READY_STATE_CHANGE);
267 }
268
269 executeDeferredScriptsIfNeeded();
270
271 executeEventHandlersIfNeeded(Event.TYPE_DOM_DOCUMENT_LOADED);
272
273 // postponed actions are more or less the async scripts,
274 // they are running in real browsers whenever the download is done
275 processPostponedActionsIfNeeded();
276
277 loadFrames();
278
279 // don't set the ready state if we really load the blank page into the window
280 // see Node.initInlineFrameIfNeeded()
281 if (!isAboutBlank) {
282 setReadyState(READY_STATE_COMPLETE);
283 getDocumentElement().setReadyState(READY_STATE_COMPLETE);
284 executeEventHandlersIfNeeded(Event.TYPE_READY_STATE_CHANGE);
285 }
286
287 // frame initialization has a different order
288 boolean isFrameWindow = enclosingWindow instanceof FrameWindow;
289 boolean isFirstPageInFrameWindow = false;
290 if (isFrameWindow) {
291 isFrameWindow = ((FrameWindow) enclosingWindow).getFrameElement() instanceof HtmlFrame;
292
293 final History hist = enclosingWindow.getHistory();
294 if (hist.getLength() > 0 && UrlUtils.URL_ABOUT_BLANK == hist.getUrl(0)) {
295 isFirstPageInFrameWindow = hist.getLength() <= 2;
296 }
297 else {
298 isFirstPageInFrameWindow = enclosingWindow.getHistory().getLength() < 2;
299 }
300 }

Callers

nothing calls this directly

Calls 15

getEnclosedPageMethod · 0.95
getDocumentElementMethod · 0.95
loadFramesMethod · 0.95
getHistoryMethod · 0.95
getLengthMethod · 0.95
getUrlMethod · 0.95
isHtmlPageMethod · 0.95
getWebClientMethod · 0.95
getBodyMethod · 0.95

Tested by

no test coverage detected