How to use iframe_loaded method in wpt

Best JavaScript code snippet using wpt

task-pr.js

Source:task-pr.js Github

copy

Full Screen

1(function () {2'use strict';3/*4 * Same domain task proxy implementation for Bebras task API - v1.0 - 08/20145 *6 * Depends on jQuery.7 *8 */9var functionsToTrigger = {load: true, unload:true, reloadAnswer:true, showViews: true, reloadState: true};10var taskProxyLoadListener = null;11function taskCaller(task, request, content, error) {12 if (!error) {13 error = function() {};14 }15 // TODO: handle case where iframe_loaded is false and caller expects a result...16 if (!task.iframe_loaded) {17 setTimeout(function() {18 taskCaller(task, request, content);19 }, 100);20 } else {21 if (task.distantTask && typeof task.distantTask[request] === 'function') {22 if (typeof content === 'string' || (typeof content === 'object' && Object.prototype.toString.call(content) !== '[object Array]')) {23 content = [content];24 }25 var askedCallbackIdx = (typeof content[content.length - 2] === 'function') ? content.length - 2 : content.length - 1;26 if (typeof content[askedCallbackIdx] !== 'function') {27 error('calls to task must contain a callback');28 return;29 }30 var oldCallback = content[askedCallbackIdx];31 var timeout = window.setTimeout(function() {32 error('timeout reached for '+request);33 }, 20000);34 var newCallback = function() {35 window.clearTimeout(timeout);36 if (functionsToTrigger[request]) {37 task.distantPlatform.trigger(request, content);38 }39 oldCallback(arguments[0], arguments[1], arguments[3]);40 };41 content[askedCallbackIdx] = newCallback;42 if (typeof window.taskPrNoCatch !== 'undefined') {43 task.distantTask[request].apply(task.distantTask, content);44 } else {45 try {46 task.distantTask[request].apply(task.distantTask, content);47 } catch (e) {48 window.clearTimeout(timeout);49 error(e.name+': '+e.message);50 }51 }52 } else if (task.distantTask) {53 error("Task "+task.Id+" doesn't implement "+request);54 } else {55 error('call to '+request+' on task with no distant task');56 }57 }58}59/*60 * Task object, created from an iframe DOM element61 */62function Task(iframe, callback) {63 this.iframe = iframe;64 this.iframe_loaded = false;65 this.distantTask = null;66 this.Id = iframe.attr('id');67 this.elementsLoaded = false;68 this.platform = null;69 var that = this;70 this.setPlatform = function(platform) {71 this.platform = platform;72 if (this.iframe_loaded) {73 this.distantPlatform.setPlatform(platform);74 }75 };76 var loadEventId = null;77 this.iframeLoaded = function() {78 if (that.iframe_loaded) {79 return;80 }81 that.iframe_loaded = true;82 that.distantTask = that.iframe[0].contentWindow.task;83 that.distantPlatform = that.iframe[0].contentWindow.platform;84 that.iframe[0].contentWindow.platform.parentLoadedFlag = true;85 if (that.platform) {86 that.distantPlatform.setPlatform(that.platform);87 }88 if(loadEventId) {89 taskProxyLoadListener(loadEventId, 'ready');90 }91 callback();92 };93 // checking if platform is already available94 var iframeDoc = that.iframe[0].contentDocument || that.iframe[0].contentWindow.document;95 if (iframeDoc && iframeDoc.readyState == 'complete' && that.iframe[0].contentWindow.platform && !that.iframe[0].contentWindow.platform.parentLoadedFlag) {96 that.iframe[0].contentWindow.platform.initCallback(that.iframeLoaded);97 } else {98 if(document.addEventListener) { // ie > 899 $(that.iframe).on("load", function() {100 that.iframe[0].contentWindow.platform.initCallback(that.iframeLoaded);101 });102 } else {103 setTimeout(function() {104 that.iframeLoaded();105 }, 100);106 }107 if(taskProxyLoadListener) {108 // If it wasn't loaded, log details109 loadEventId = Math.floor(Math.random() * 100000);110 taskProxyLoadListener(loadEventId, 'notready', !!iframeDoc + ',' + iframeDoc.readyState + ',' + !!that.iframe[0].contentWindow.platform + ',' + !that.iframe[0].contentWindow.platform.parentLoadedFlag + ';listener:' + !!document.addEventListener);111 setTimeout(function () {112 taskProxyLoadListener(loadEventId, 'notready2', !!iframeDoc + ',' + iframeDoc.readyState + ',' + !!that.iframe[0].contentWindow.platform + ',' + !that.iframe[0].contentWindow.platform.parentLoadedFlag + ';listener:' + !!document.addEventListener);113 }, 1000);114 }115 }116}117Task.prototype.getSourceId = function() {118 return this.Id;119};120Task.prototype.getTargetUrl = function() {121 return this.iframe.attr('src');122};123Task.prototype.getTarget = function() {124 return this.iframe[0].contentWindow;125};126Task.prototype.getDomain = function() {127 var url = this.getTargetUrl();128 return url.substr(0, url.indexOf('/', 7));129};130/**131 * Task API functions132 */133Task.prototype.load = function(views, success, error) {134 return taskCaller(this, 'load', [views, success, error], error);135};136Task.prototype.unload = function(success, error) {137 return taskCaller(this, 'unload', [success, error], error);138};139Task.prototype.getHeight = function(success, error) {140 return taskCaller(this, 'getHeight', [success, error], error);141};142Task.prototype.updateToken = function(token, success, error) {143 return taskCaller(this, 'updateToken', [token, success, error], error);144};145Task.prototype.getAnswer = function(success, error) {146 return taskCaller(this, 'getAnswer', [success, error], error);147};148Task.prototype.reloadAnswer = function(answer, success, error) {149 return taskCaller(this, 'reloadAnswer', [answer, success, error], error);150};151Task.prototype.getState = function(success, error) {152 return taskCaller(this, 'getState', [success, error], error);153};154Task.prototype.reloadState = function(state, success, error) {155 return taskCaller(this, 'reloadState', [state, success, error], error);156};157Task.prototype.getViews = function(success, error) {158 return taskCaller(this, 'getViews', [success, error], error);159};160Task.prototype.getMetaData = function(success, error) {161 return taskCaller(this, 'getMetaData', [success, error], error);162};163Task.prototype.showViews = function(views, success, error) {164 return taskCaller(this, 'showViews', [views, success, error], error);165};166// TODO: put error back in argument list, for this 2015 tasks must be changed167Task.prototype.gradeAnswer = function(answer, answerToken, success, error) {168 return taskCaller(this, 'gradeAnswer', [answer, answerToken, success], error);169};170Task.prototype.getResources = function(success, error) {171 return taskCaller(this, 'getResources', [success, error], error);172};173// for grader.gradeTask174// TODO: put error back in argument list, for this 2015 tasks must be changed175Task.prototype.gradeTask = function(answer, answerToken, success, error) {176 return taskCaller(this, 'gradeTask', [answer, answerToken, success], error);177};178window.TaskProxyManager = {179 tasks: {},180 platforms: {},181 getTaskProxy: function(idFrame, callback, force) {182 if (!force && TaskProxyManager.tasks[idFrame]) {183 callback(TaskProxyManager.tasks[idFrame]);184 } else {185 if (force) {186 TaskProxyManager.deleteTaskProxy(idFrame);187 }188 $('#'+idFrame).each(function() {189 TaskProxyManager.tasks[idFrame] = new Task($(this), function() {setTimeout(function() {190 if (idFrame in TaskProxyManager.platforms) {191 TaskProxyManager.tasks[idFrame].setPlatform(TaskProxyManager.platforms[idFrame]);192 }193 callback(TaskProxyManager.tasks[idFrame]);194 });});195 });196 }197 },198 setPlatform: function(task, platform) {199 TaskProxyManager.platforms[task.Id] = platform;200 TaskProxyManager.tasks[task.Id].setPlatform(platform);201 },202 deleteTaskProxy: function(idFrame) {203 delete(TaskProxyManager.tasks[idFrame]);204 delete(TaskProxyManager.platforms[idFrame]);205 },206 getUrl: function(taskUrl, sToken, sPlatform, prefix, sLocale) {207 var url = taskUrl+'?sToken='+encodeURIComponent(sToken)+'&sPlatform='+encodeURIComponent(sPlatform);208 if(sLocale) { url += '&sLocale='+encodeURIComponent(sLocale); }209 return url;210 },211 bindListener: function(listener) {212 // (Temporary?) function to bind a listener, which will be called when213 // some load events happen214 taskProxyLoadListener = listener;215 }216};217window.TaskProxyManager.getGraderProxy = TaskProxyManager.getTaskProxy;218}());219/*220 * Platform object definition, created from a Task object (see below)221 */222function Platform(task) {223 this.task = task;224}225Platform.prototype.getTask = function() {226 return this.task;227};228/*229 * Simple prototypes for platform API functions, to be overriden by your230 * platform's specific functions (for each platform object)231 */232Platform.prototype.validate = function(mode) {};233Platform.prototype.showView = function(views) {};234Platform.prototype.askHint = function(platformToken) {};235Platform.prototype.updateHeight = function(height) { this.updateDisplay({height: height}); }; // Legacy236Platform.prototype.updateDisplay = function(data) {237 if(data.height) {238 this.task.iframe.height(parseInt(height)+40);239 }240};241Platform.prototype.log = function(data) {};242Platform.prototype.getTaskParams = function(key, defaultValue, success, error) {243 var res = {minScore: -3, maxScore: 10, randomSeed: 0, noScore: 0, readOnly: false, options: {}};244 if (key) {245 if (key !== 'options' && key in res) {246 res = res[key];247 } else if (res.options && key in res.options) {248 res = res.options[key];249 } else {250 res = (typeof defaultValue !== 'undefined') ? defaultValue : null;251 }252 }253 success(res);254};255Platform.prototype.openUrl = function(url) {256 // TODO257};...

Full Screen

Full Screen

navigation.js

Source:navigation.js Github

copy

Full Screen

1// Navigation object, used to go to activities, screens and pages, and to keep track of the navigation path2var Navigation = Class({3 // Construction method4 create: function(){5 this.current_activity = 'core';6 this.current_screen = '';7 this.current_page = ''; 8 this.iframe_loaded = false;9 this.history = [];10 // Detect changes in the URL11 var _that = this;12 $(window).bind('hashchange', function(){13 var hash = window.location.hash;14 _that.go_hash(hash);15 });16 }, 17 18 // Go to a specific path19 go: function( path, parameters ){20 // Save this new location to the history 21 this.history.push([path, parameters]); 22 // Break down path23 var path = path.split("/");24 var activity = path[1] || '';25 var screen = path[2] || ''; 26 var page = path[3] || '';27 var location_changed = false;28 console.log([activity,screen,page]);29 // TODO : Handle activity, screen and page exits30 // Go to the right activity31 // TODO : Handle non-existing activities32 if( this.current_activity != activity ){33 this.current_activity = activity;34 screens.activity.enter(activity);35 location_changed = true;36 this.iframe_loaded = false;37 }else{38 }39 // Go to the right screen40 // TODO : Handle non-existing screens41 if( this.current_screen != screen || this.current_page != page ){42 // Go to a new screen43 if( this.current_activity == 'core' ){44 this.current_screen = screen;45 if( page == '' ){46 // No page specified, enter the screen47 screens[screen].enter(parameters);48 }else{49 // Page specified, enter that page50 screens[screen][page].call(screens[screen],parameters);51 }52 location_changed = true;53 }else{54 this.current_screen = screen;55 if( this.iframe_loaded == false ){56 var _that = this;57 $("#activity_iframe").on("load", function(){58 _that.iframe_loaded = true;59 if( page == '' ){60 // No page specified, enter the screen61 window.frames[0].screens[screen].enter(parameters);62 }else{63 // Page specified, enter that page64 window.frames[0].screens[screen][page].call(window.frames[0].screens[screen],parameters);65 }66 location_changed = true;67 });68 }else{69 if( page == '' ){70 // No page specified, enter the screen71 window.frames[0].screens[screen].enter(parameters);72 }else{73 // Page specified, enter that page74 window.frames[0].screens[screen][page].call(window.frames[0].screens[screen],parameters);75 }76 location_changed = true;77 }78 }79 }else{80 }81 // TODO : Handle pages82 83 // TODO : Handle parameters84 if( location_changed == true ){85 window.location.hash = "#" + path.join('/');86 }87 },88 // Go back one step89 go_back: function(){90 // Pop this page91 this.history.pop();92 // Pop previous page93 var previous = this.history.pop();94 95 // Go there again96 this.go(previous[0],previous[1]);97 },98 // Go to a specific hash99 go_hash: function(hash){100 var cut = hash.split('#')[1].split('?'); 101 var path = cut[0];102 var parameters = cut[1];103 // TODO : Handle parameters104 // Do not go to a path we are already at105 if( path == this.history[this.history.length-1][0] ){ return; } 106 this.go(path);107 }108}); 109// TODO : If in activity use the parent's machine instead...

Full Screen

Full Screen

zz.js

Source:zz.js Github

copy

Full Screen

1const IFRAME_LOADED = 'iframe loaded';2const et = new EventTarget;3const iframeLoadPromise = new Promise((resolve, reject) => {4 et.addEventListener(IFRAME_LOADED, e => {5 resolve(e.detail);6 });7});8export const init = iframeUrl => {9 const _iframe = document.createElement('iframe');10 _iframe.style.display = 'none';11 _iframe.src = iframeUrl;12 document.body.appendChild(_iframe);13 _iframe.addEventListener('load', () => {14 et.dispatchEvent(new CustomEvent(IFRAME_LOADED, {15 detail: {16 iframe: _iframe,17 url: new URL(iframeUrl),18 },19 }));20 });21};22export const login = (username, password) => new Promise((resolve, reject) => {23 iframeLoadPromise.then(({iframe, url}) => {24 iframe.contentWindow.postMessage({type: 'login'}, url.origin);25 window.addEventListener('message', ({data: {type, userInfo}}) => {26 resolve({type, userInfo});27 });28 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1function iframe_loaded(iframe_id) {2 var iframe = document.getElementById(iframe_id);3 var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;4 if (iframeDoc.readyState == "complete") {5 return true;6 }7 return false;8}9function checkIframeLoaded(iframe_id) {10 if (iframe_loaded(iframe_id)) {11 } else {12 setTimeout(function () { checkIframeLoaded(iframe_id); }, 100);13 }14}15checkIframeLoaded("iframe_id");

Full Screen

Using AI Code Generation

copy

Full Screen

1function iframe_loaded(iframe_id, callback) {2 var iframe = document.getElementById(iframe_id);3 if (iframe) {4 if (iframe.contentDocument && iframe.contentDocument.readyState === "complete") {5 callback();6 } else {7 iframe.onload = callback;8 }9 }10};11iframe_loaded("iframe_id", function() {12});

Full Screen

Using AI Code Generation

copy

Full Screen

1window.wptdriver.iframe_loaded();2window.wptdriver.iframe_load_failed();3window.wptdriver.iframe_load_timeout();4window.wptdriver.iframe_load_error();5window.wptdriver.iframe_loaded();6window.wptdriver.iframe_load_failed();7window.wptdriver.iframe_load_timeout();8window.wptdriver.iframe_load_error();9window.wptdriver.iframe_loaded();10window.wptdriver.iframe_load_failed();11window.wptdriver.iframe_load_timeout();12window.wptdriver.iframe_load_error();13window.wptdriver.iframe_loaded();14window.wptdriver.iframe_load_failed();15window.wptdriver.iframe_load_timeout();16window.wptdriver.iframe_load_error();17window.wptdriver.iframe_loaded();18window.wptdriver.iframe_load_failed();19window.wptdriver.iframe_load_timeout();20window.wptdriver.iframe_load_error();21window.wptdriver.iframe_loaded();22window.wptdriver.iframe_load_failed();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2wptdriver.iframe_loaded("iframe", function() {3 wptdriver.log("iframe loaded");4 wptdriver.done();5});6var wptdriver = require('wptdriver');7wptdriver.waitForIframeLoaded("iframe", function() {8 wptdriver.log("iframe loaded");9 wptdriver.done();10});11### wptdriver.waitForIframeLoaded(iframeId, callback)12var wptdriver = require('wptdriver');13wptdriver.waitForIframeLoaded("iframe", function() {14 wptdriver.log("iframe loaded");15 wptdriver.done();16});17### wptdriver.waitForIframeLoadedByIndex(iframeIndex, callback)18var wptdriver = require('wptdriver');19wptdriver.waitForIframeLoadedByIndex(0, function() {20 wptdriver.log("iframe loaded");21 wptdriver.done();22});23### wptdriver.waitForIframeLoadedByName(iframeName, callback)24var wptdriver = require('wptdriver');25wptdriver.waitForIframeLoadedByName("iframeName", function() {26 wptdriver.log("iframe loaded");27 wptdriver.done();28});29### wptdriver.waitForIframeLoadedByURL(iframeURL, callback)30var wptdriver = require('wptdriver');

Full Screen

Using AI Code Generation

copy

Full Screen

1iframe_loaded: function(url) {2 if (this.iframe_loaded_urls[url] === undefined) {3 this.iframe_loaded_urls[url] = 1;4 } else {5 this.iframe_loaded_urls[url]++;6 }7 this.log("iframe_loaded: " + url + " count: " + this.iframe_loaded_urls[url]);8 this.check_iframe_loaded_urls();9},10check_iframe_loaded_urls: function() {11 var all_loaded = true;12 for (var url in this.iframe_loaded_urls) {13 if (this.iframe_loaded_urls[url] < 2) {14 all_loaded = false;15 break;16 }17 }18 if (all_loaded) {19 this.log("all iframes loaded");20 this.iframe_loaded_urls = {};21 this.sendCommand("IFRAME_LOADED");22 }23},24void WptDriver::OnIframeLoaded() {25 if (_video_capture)26 _video_capture->CapturePage();27 _browser_info->iframe_loaded = true;28 _browser_info->iframe_loaded_url = "";29 _browser_info->iframe_loaded_count = 0;30 _browser_info->iframe_loaded_urls.clear();31 _browser_info->iframe_loaded_urls_map.clear();32}33void WptDriver::OnIframeLoadedUrl(CString url, int count) {34 if (_video_capture)35 _video_capture->CapturePage();36 _browser_info->iframe_loaded = true;37 _browser_info->iframe_loaded_url = url;38 _browser_info->iframe_loaded_count = count;39 _browser_info->iframe_loaded_urls.push_back(url);40 _browser_info->iframe_loaded_urls_map[url] = count;41}42void WptDriver::OnIframeLoadedUrls(CAtlList<CString>& urls) {43 if (_video_capture)44 _video_capture->CapturePage();45 _browser_info->iframe_loaded = true;46 _browser_info->iframe_loaded_url = "";47 _browser_info->iframe_loaded_count = 0;48 for (POSITION pos = urls.GetHeadPosition(); pos != NULL;) {49 CString url = urls.GetNext(pos);50 if (_browser_info->iframe_loaded

Full Screen

Using AI Code Generation

copy

Full Screen

1window.iframe_loaded = function(iframe_id, frame_id) {2}3window.iframe_loaded = function(iframe_id, frame_id) {4}5window.iframe_loaded = function(iframe_id, frame_id) {6}7window.iframe_loaded = function(iframe_id, frame_id) {8}9window.iframe_loaded = function(iframe_id, frame_id) {10}11window.iframe_loaded = function(iframe_id, frame_id) {12}13window.iframe_loaded = function(iframe_id, frame_id) {14}15window.iframe_loaded = function(iframe_id, frame_id) {16}17window.iframe_loaded = function(iframe_id, frame_id) {18}19window.iframe_loaded = function(iframe_id, frame_id) {20}21window.iframe_loaded = function(iframe_id, frame_id) {22}23window.iframe_loaded = function(iframe_id, frame_id) {24}25window.iframe_loaded = function(iframe_id, frame_id) {26}27window.iframe_loaded = function(iframe_id, frame_id) {28}29window.iframe_loaded = function(

Full Screen

Using AI Code Generation

copy

Full Screen

1function iframe_loaded() {2 return true;3}4function set_user_agent() {5 return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";6}7function set_window_size() {8 return {width: 1920, height: 1080};9}10function set_window_position() {11 return {x: 0, y: 0};12}13function set_window_state() {14 return "maximized";15}16function set_http_headers() {17 return {18 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like

Full Screen

Using AI Code Generation

copy

Full Screen

1function iframe_loaded() {2 return document.getElementById('myIframe').contentWindow.document.readyState == 'complete';3}4function run_test() {5}6function iframe_loaded() {7 return document.getElementById('myIframe').contentWindow.document.readyState == 'complete';8}9function run_test() {10}11function iframe_loaded() {12 return document.getElementById('myIframe').contentWindow.document.readyState == 'complete';13}14function run_test() {15}

Full Screen

Using AI Code Generation

copy

Full Screen

1var iframe_loaded = function(iframe, callback) {2 if (iframe.contentWindow.document.readyState == 'complete') {3 callback();4 } else {5 setTimeout(function() { iframe_loaded(iframe, callback); }, 10);6 }7};8var iframe_loaded = function(iframe, callback) {9 if (iframe.contentWindow.document.readyState == 'complete') {10 callback();11 } else {12 setTimeout(function() { iframe_loaded(iframe, callback); }, 10);13 }14};15var iframe_loaded = function(iframe, callback) {16 if (iframe.contentWindow.document.readyState == 'complete') {17 callback();18 } else {19 setTimeout(function() { iframe_loaded(iframe, callback); }, 10);20 }21};22var iframe_loaded = function(iframe, callback) {23 if (iframe.contentWindow.document.readyState == 'complete') {24 callback();25 } else {26 setTimeout(function() { iframe_loaded(iframe, callback); }, 10);27 }28};29var iframe_loaded = function(iframe, callback) {30 if (iframe.contentWindow.document.readyState == 'complete') {31 callback();32 } else {33 setTimeout(function() { iframe_loaded(iframe, callback); }, 10);34 }35};36var iframe_loaded = function(iframe

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = function(driver, By, until, configuration) {2 .then(_ => driver.wait(until.iframeLoaded(By.css('iframe#testFrame'))))3 .then(_ => driver.switchTo().frame('testFrame'))4 .then(_ => driver.wait(until.iframeLoaded(By.css('iframe#innerFrame'))))5 .then(_ => driver.switchTo().frame('innerFrame'))6 .then(_ => driver.wait(until.elementLocated(By.id('loaded'))))7 .then(_ => driver.findElement(By.id('loaded')).getText())8 .then(text => {9 if (text != 'loaded')10 throw new Error('iframe did not load');11 });12};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful