Best JavaScript code snippet using playwright-internal
HistoryWithHash-test.js
Source:HistoryWithHash-test.js
...171 href: '/currentUrl'172 }173 });174 var history = new HistoryWithHash({win: win});175 history.pushState({foo: 'bar'});176 expect(testResult.pushState.state).to.eql({foo: 'bar'});177 expect(testResult.pushState.title).to.equal('current title');178 expect(testResult.pushState.url).to.equal('/currentUrl');179 history.pushState({foo: 'bar'}, 't', '/url');180 expect(testResult.pushState.state).to.eql({foo: 'bar'});181 expect(testResult.pushState.title).to.equal('t');182 expect(testResult.pushState.url).to.equal('/url');183 expect(windowMock.HTML5.document.title).to.equal('t');184 history.pushState({foo: 'bar'}, 'tt', '/url?a=b&x=y');185 expect(testResult.pushState.state).to.eql({foo: 'bar'});186 expect(testResult.pushState.title).to.equal('tt');187 expect(testResult.pushState.url).to.equal('/url?a=b&x=y');188 expect(windowMock.HTML5.document.title).to.equal('tt');189 });190 it ('useHashRoute=false; has pushState; Firefox', function () {191 var win = _.extend(windowMock.Firefox, {192 'document': {193 title: 'current title'194 },195 location: {196 href: '/currentUrl'197 }198 });199 var history = new HistoryWithHash({win: win});200 history.pushState({foo: 'bar'});201 expect(testResult.pushState.state).to.eql({foo: 'bar'});202 expect(testResult.pushState.title).to.equal('current title');203 expect(testResult.pushState.url).to.equal('/currentUrl');204 history.pushState({foo: 'bar'}, 't', '/url');205 expect(testResult.pushState.state).to.eql({foo: 'bar'});206 expect(testResult.pushState.title).to.equal('t');207 expect(testResult.pushState.url).to.equal('/url');208 });209 it ('useHashRoute=false; no pushState', function () {210 var win = _.extend({}, windowMock.OLD, {location: {}});211 var history = new HistoryWithHash({212 win: win,213 useHashRoute: false214 });215 history.pushState({foo: 'bar'}, 't', '/url');216 expect(win.location.href).to.equal('/url');217 history.pushState({foo: 'bar'}, 't', '/url?a=b&x=y');218 expect(win.location.href).to.equal('/url?a=b&x=y');219 });220 it ('useHashRoute=true; has pushState', function () {221 var win = _.extend({}, windowMock.HTML5, {222 location: {223 pathname: '/path',224 search: '?a=b'225 }226 });227 var history = new HistoryWithHash({win: win, useHashRoute: true});228 history.pushState({foo: 'bar'}, 't', '/url');229 expect(testResult.pushState.state).to.eql({foo: 'bar'});230 expect(testResult.pushState.title).to.equal('t');231 expect(testResult.pushState.url).to.equal('/path?a=b#/url');232 history.pushState({foo: 'bar'}, 't', '/url?a=b&x=y');233 expect(testResult.pushState.state).to.eql({foo: 'bar'});234 expect(testResult.pushState.title).to.equal('t');235 expect(testResult.pushState.url).to.equal('/path?a=b#/url?a=b&x=y');236 });237 it ('useHashRoute=true; has pushState; has hashRouteTransformer', function () {238 var win = _.extend({}, windowMock.HTML5, {239 location: {240 pathname: '/path',241 search: '?a=b'242 }243 });244 var history = new HistoryWithHash({245 win: win,246 useHashRoute: true,247 hashRouteTransformer: {248 transform: function (hash) {249 return hash.replace(/\//g, '-');250 }251 }252 });253 history.pushState({foo: 'bar'}, 't', '/url');254 expect(testResult.pushState.state).to.eql({foo: 'bar'});255 expect(testResult.pushState.title).to.equal('t');256 expect(testResult.pushState.url).to.equal('/path?a=b#-url');257 history.pushState({foo: 'bar'}, 't', '/url?a=b&x=y');258 expect(testResult.pushState.state).to.eql({foo: 'bar'});259 expect(testResult.pushState.title).to.equal('t');260 expect(testResult.pushState.url).to.equal('/path?a=b#-url?a=b&x=y');261 });262 it ('useHashRoute=true; no pushState', function () {263 var win = _.extend({}, windowMock.OLD, {264 location: {}265 });266 var history = new HistoryWithHash({win: win, useHashRoute: true});267 history.pushState({foo: 'bar'}, 't', '/url');268 expect(win.location.hash).to.equal('#/url');269 history.pushState({foo: 'bar'}, 't', '/url?a=b&x=y');270 expect(win.location.hash).to.equal('#/url?a=b&x=y');271 });272 });273 describe('replaceState', function () {274 it ('useHashRouter=false; has pushState', function () {275 // var history = new HistoryWithHash({win: windowMock.HTML5});276 var win = _.extend(windowMock.HTML5, {277 'document': {278 title: 'current title'279 },280 location: {281 href: '/currentUrl'282 }283 });...
History-test.js
Source:History-test.js
...185 href: '/currentUrl'186 }187 });188 var history = new History({win: win});189 history.pushState({foo: 'bar'});190 expect(testResult.pushState.state).to.eql({origUrl: '/currentUrl', foo: 'bar'});191 expect(testResult.pushState.title).to.equal('current title');192 expect(testResult.pushState.url).to.equal('/currentUrl');193 history.pushState({foo: 'bar'}, 't');194 expect(testResult.pushState.state).to.eql({origUrl: '/currentUrl', foo: 'bar'});195 expect(testResult.pushState.title).to.equal('t');196 expect(testResult.pushState.url).to.equal('/currentUrl');197 history.pushState({foo: 'bar'}, 't', '/url');198 expect(testResult.pushState.state).to.eql({origUrl: '/url', foo: 'bar'});199 expect(testResult.pushState.title).to.equal('t');200 expect(testResult.pushState.url).to.equal('/url');201 expect(windowMock.HTML5.document.title).to.equal('t');202 history.pushState({foo: 'bar'}, 'tt', '/url?a=b&x=y');203 expect(testResult.pushState.state).to.eql({origUrl: '/url?a=b&x=y', foo: 'bar'});204 expect(testResult.pushState.title).to.equal('tt');205 expect(testResult.pushState.url).to.equal('/url?a=b&x=y');206 expect(windowMock.HTML5.document.title).to.equal('tt');207 var unicodeUrl = '/post/128097060420/2015-fno-vogueå
¨çè³¼ç©å¤-ç¾è人å人å
±è¥çè';208 history.pushState({foo: 'bar'}, 'tt', unicodeUrl);209 expect(testResult.pushState.state).to.eql({origUrl: unicodeUrl, foo: 'bar'});210 expect(testResult.pushState.title).to.equal('tt');211 expect(testResult.pushState.url).to.equal(unicodeUrl);212 expect(windowMock.HTML5.document.title).to.equal('tt');213 });214 it ('has pushState, Firefox', function () {215 var win = _.extend(windowMock.Firefox, {216 'document': {217 title: 'current title'218 },219 location: {220 href: '/currentUrl'221 }222 });223 var history = new History({win: win});224 history.pushState({foo: 'bar'});225 expect(testResult.pushState.state).to.eql({origUrl: '/currentUrl', foo: 'bar'});226 expect(testResult.pushState.title).to.equal('current title');227 expect(testResult.pushState.url).to.equal('/currentUrl');228 history.pushState({foo: 'bar'}, 't');229 expect(testResult.pushState.state).to.eql({origUrl: '/currentUrl', foo: 'bar'});230 expect(testResult.pushState.title).to.equal('t');231 expect(testResult.pushState.url).to.equal('/currentUrl');232 history.pushState({foo: 'bar'}, 't', '/url');233 expect(testResult.pushState.state).to.eql({origUrl: '/url', foo: 'bar'});234 expect(testResult.pushState.title).to.equal('t');235 expect(testResult.pushState.url).to.equal('/url');236 });237 it ('no pushState', function () {238 var win = _.extend(windowMock.OLD, {239 location: {}240 });241 var history = new History({win: win});242 history.pushState({foo: 'bar'}, 't', '/url');243 expect(win.location.href).to.equal('/url');244 history.pushState({foo: 'bar'}, 't', '/url?a=b&x=y');245 expect(win.location.href).to.equal('/url?a=b&x=y');246 history.pushState({foo: 'bar'});247 expect(win.location.href).to.equal('/url?a=b&x=y');248 });249 });250 describe('replaceState', function () {251 it ('has pushState', function () {252 var win = _.extend(windowMock.HTML5, {253 'document': {254 title: 'current title'255 },256 location: {257 href: '/currentUrl'258 }259 });260 var history = new History({win: win});...
pushstate_spec.js
Source:pushstate_spec.js
1define([ "jquery", "public/assets/javascripts/lib/page/pushstate.js" ], function($, Pushstate) {2 "use strict";3 var pushstate, serialized, newParams, deserialized,4 listener = $("#js-card-holder");5 serialized = {6 url: "http://www.lonelyplanet.com/france/paris/hotels",7 urlWithSearchAndFilters: "http://www.lonelyplanet.com/england/london/hotels?utf8=â&search%5Bpage_offsets%5D=0%2C58&search%5Bfrom%5D=29+May+2013&search%5Bto%5D=30+May+2013&search%5Bguests%5D=2&search%5Bcurrency%5D=USD&filters%5Bproperty_type%5D%5B3star%5D=true&filters%5Blp_reviewed%5D=true",8 urlParams: "utf8=â&search%5Bfrom%5D=29+May+2013&search%5Bto%5D=30+May+2013&search%5Bguests%5D=2&search%5Bcurrency%5D=USD&filters%5Bproperty_type%5D%5B3star%5D=true&filters%5Blp_reviewed%5D=true",9 newUrlWithSearchAndFilters: "filters%5Bproperty_type%5D%5B4star%5D=true"10 };11 deserialized = {12 utf8: "â",13 search: {14 from: "29 May 2013",15 to: "30 May 2013",16 guests: "2",17 currency: "USD"18 },19 filters: {20 property_type: {21 "3star": "true"22 },23 lp_reviewed: "true"24 }25 };26 newParams = {27 filters: {28 property_type: {29 "4star": true30 }31 },32 pagination: {33 page_offsets: 234 }35 };36 describe("Pushstate", function() {37 beforeEach(function() {38 pushstate = new Pushstate();39 });40 describe("initialisation without support for history.pushState", function() {41 beforeEach(function() {42 window.pushstate = new Pushstate();43 spyOn(pushstate, "_supportsHistory").and.returnValue(false);44 spyOn(pushstate, "_onHashChange");45 pushstate.popStateFired = false;46 pushstate._initHistory();47 });48 it("calls _onHashChange", function() {49 $(window).trigger("hashchange");50 expect(pushstate._onHashChange).toHaveBeenCalled();51 });52 });53 describe("creating the url", function() {54 beforeEach(function() {55 window.pushstate = new Pushstate();56 spyOn(pushstate, "getParams").and.returnValue(serialized.newUrlWithSearchAndFilters);57 });58 describe("with pushState support", function() {59 it("serializes the application state with the document root", function() {60 var newUrl;61 newUrl = pushstate._createUrl(serialized.newUrlWithSearchAndFilters, "/");62 expect(newUrl).toBe("/?" + serialized.newUrlWithSearchAndFilters);63 });64 it("serializes the application state with the *new* document root", function() {65 var newUrl;66 newUrl = pushstate._createUrl(serialized.newUrlWithSearchAndFilters, "/reviewed");67 expect(newUrl).toBe("/reviewed?" + serialized.newUrlWithSearchAndFilters);68 });69 });70 describe("without pushState support", function() {71 beforeEach(function() {72 spyOn(pushstate, "_supportsHistory").and.returnValue(false);73 });74 it("creates a hashbang url with the document root", function() {75 var newUrl;76 newUrl = pushstate._createUrl(serialized.newUrlWithSearchAndFilters, "/");77 expect(newUrl).toBe("#!/" + "?" + serialized.newUrlWithSearchAndFilters);78 });79 it("creates a hashbang url with the *new* document root", function() {80 var newUrl;81 newUrl = pushstate._createUrl(serialized.newUrlWithSearchAndFilters, "/reviewed");82 expect(newUrl).toBe("#!/reviewed" + "?" + serialized.newUrlWithSearchAndFilters);83 });84 });85 });86 describe("updating push state", function() {87 var initialSlug = null;88 beforeEach(function() {89 initialSlug = window.location.pathname;90 window.pushstate = new Pushstate();91 pushstate.navigate("", "/test");92 });93 it("changes current location", function() {94 expect(window.location.pathname).toEqual("/test");95 });96 afterEach(function() {97 window.history.replaceState({}, null, initialSlug)98 });99 });100 describe("updating hash bang", function() {101 beforeEach(function() {102 window.pushstate = new Pushstate();103 spyOn(pushstate, "_supportsHistory").and.returnValue(false);104 spyOn(pushstate, "_supportsHash").and.returnValue(true);105 spyOn(pushstate, "setHash");106 pushstate.navigate("", "/test");107 });108 afterEach(function() {109 window.location.hash = "";110 });111 it("the hash is appended to the url", function() {112 expect(pushstate.setHash).toHaveBeenCalledWith("#!/test");113 });114 });115 describe("when we dont support pushState", function() {116 beforeEach(function() {117 window.pushstate = new Pushstate();118 spyOn(pushstate, "_supportsHistory").and.returnValue(false);119 });120 describe("when we have a hash", function() {121 beforeEach(function() {122 spyOn(pushstate, "getHash").and.returnValue("#!/testing");123 spyOn(pushstate, "setUrl");124 });125 describe("and history navigation is enabled", function() {126 beforeEach(function() {127 pushstate.allowHistoryNav = true;128 pushstate._onHashChange();129 });130 it("replaces the url with the stored hash url", function() {131 expect(pushstate.setUrl).toHaveBeenCalledWith("/testing");132 });133 });134 describe("and history navigation is disabled", function() {135 beforeEach(function() {136 pushstate.allowHistoryNav = false;137 pushstate._onHashChange();138 });139 it("does not update the url", function() {140 expect(pushstate.getHash).not.toHaveBeenCalled();141 expect(pushstate.setUrl).not.toHaveBeenCalled();142 });143 });144 });145 describe("when we dont have a hash and history navigation is enabled", function() {146 beforeEach(function() {147 spyOn(pushstate, "getHash").and.returnValue("");148 spyOn(pushstate, "getUrl").and.returnValue("www.lonelyplanet.com/testing");149 spyOn(pushstate, "setUrl");150 pushstate.allowHistoryNav = true;151 pushstate._onHashChange();152 });153 it("replaces the url with the current url", function() {154 expect(pushstate.setUrl).toHaveBeenCalledWith("www.lonelyplanet.com/testing");155 });156 });157 });158 // --------------------------------------------------------------------------159 // Back / Forward160 // --------------------------------------------------------------------------161 describe("on first load", function() {162 beforeEach(function() {163 window.pushstate = new Pushstate();164 spyOn(pushstate, "setUrl");165 pushstate.popStateFired = false;166 pushstate._handlePopState();167 });168 it("does not refresh the page", function() {169 expect(pushstate.setUrl).not.toHaveBeenCalled();170 });171 });172 describe("after first load", function() {173 beforeEach(function() {174 window.pushstate = new Pushstate();175 spyOn(pushstate, "getUrl").and.returnValue("http://www.lonelyplanet.com/england/london?search=foo");176 spyOn(pushstate, "setUrl");177 pushstate.popStateFired = false;178 pushstate.currentUrl = "http://www.lonelyplanet.com/england/london";179 pushstate._handlePopState();180 });181 it("refreshes the page", function() {182 expect(pushstate.setUrl).toHaveBeenCalled();183 });184 });185 describe("returning to the first page", function() {186 beforeEach(function() {187 window.pushstate = new Pushstate();188 spyOn(pushstate, "getUrl").and.returnValue("http://www.lonelyplanet.com/england/london");189 spyOn(pushstate, "setUrl");190 pushstate.popStateFired = true;191 pushstate.currentUrl = "http://www.lonelyplanet.com/england/london";192 pushstate._handlePopState();193 });194 it("refreshes the page", function() {195 expect(pushstate.setUrl).toHaveBeenCalled();196 });197 });198 });...
PushPreview.react.js
Source:PushPreview.react.js
1/*2 * Copyright (c) 2016-present, Parse, LLC3 * All rights reserved.4 *5 * This source code is licensed under the license found in the LICENSE file in6 * the root directory of this source tree.7 */8import * as PushConstants from 'dashboard/Push/PushConstants';9import ParseApp from 'lib/ParseApp';10import React from 'react';11import SegmentSelect from 'components/SegmentSelect/SegmentSelect.react';12import styles from 'components/PushPreview/PushPreview.scss';13import VisiblePreview from 'components/PushPreview/VisiblePreview.react';14import {15 getDateMethod,16 MONTHS,17 pad,18 } from 'lib/DateUtils';19let Row = ({ label, content }) => (20 <div className={styles.row}>21 <div className={styles.rowLabel}>{label}</div>22 <div className={styles.rowContent}>{content}</div>23 </div>24);25let timeString = (time, isLocal) => {26 if (time && time.constructor === Date) {27 return (28 <div>29 {MONTHS[time[getDateMethod(isLocal, 'getMonth')]()].substr(0, 3) + ' ' + time[getDateMethod(isLocal, 'getDate')]()}30 <span> at </span>31 {time[getDateMethod(isLocal, 'getHours')]()}:{pad(time[getDateMethod(isLocal, 'getMinutes')]())}32 </div>33 );34 }35}36export default class PushPreview extends React.Component {37 constructor(props) {38 super(props);39 this.state = {40 currentPreview: 'iOS',41 currentTest: 'Group A',42 };43 }44 render() {45 let pushState = this.props.pushState;46 let isExperiment = !!pushState.exp_enable;47 let audienceName = 'Everyone';48 let count = -1;49 if (pushState.audience_id === 'new_segment') {50 audienceName = 'New Segment';51 } else if (pushState.audience_id !== 'everyone' &&52 this.props.audiences &&53 this.props.audiences.data &&54 this.props.audiences.data.get('audiences')55 ) {56 this.props.audiences.data.get('audiences').forEach((a) => {57 if (a.objectId === pushState.audience_id) {58 audienceName = a.name;59 count = a.size;60 return false;61 }62 });63 }64 let messagePreview = (65 <div className={styles.section}>66 <div className={styles.title}>Message</div>67 <Row label='Message:' content={pushState.data} />68 {pushState.increment_badge ? <Row label='Badge:' content='Increment' /> : null}69 </div>70 );71 if (isExperiment && pushState.exp_type === 'message') {72 messagePreview = (73 <div className={styles.section}>74 <div className={styles.title}>A/B Test</div>75 <Row label='Name:' content={pushState.experiment_name} />76 <Row label='Testing:' content='Message' />77 <Row label='Message A:' content={pushState.data1} />78 <Row label='Message B:' content={pushState.data2} />79 {pushState.increment_badge ? <Row label='Badge:' content='Increment' /> : null}80 <Row label='Test size:' content={pushState.exp_size_in_percent + '%'} />81 </div>82 );83 }84 let expiration = 'Never';85 if (pushState.push_expires) {86 if (pushState.expiration_time_type === 'time') {87 expiration = timeString(pushState.expiration_time, pushState.local_time);88 } else {89 expiration = pushState.expiration_interval_num + ' ' + pushState.expiration_interval_unit;90 }91 }92 let timePreview = (93 <div className={styles.section}>94 <div className={styles.title}>Delivery</div>95 <Row label='Time:' content={pushState.push_time_type === 'now' ? 'Immediately' : timeString(pushState.push_time_iso, pushState.local_time)} />96 <Row label='Time Zone:' content={pushState.local_time ? 'User' : 'GMT'} />97 <Row label='Expiration:' content={expiration} />98 </div>99 );100 //TODO: clarify use of UTC or GMT as GMT is time zone and UTC is standard101 if (isExperiment && pushState.exp_type === 'time') {102 timePreview = (103 <div className={styles.section}>104 <div className={styles.title}>A/B Test</div>105 <Row label='Name:' content={pushState.experiment_name} />106 <Row label='Testing:' content='Time' />107 <Row label='Time A:' content={timeString(pushState.push_time_1_iso, pushState.local_time)} />108 <Row label='Time B:' content={timeString(pushState.push_time_2_iso, pushState.local_time)} />109 <Row label='Time Zone:' content={pushState.local_time ? 'User' : 'GMT'} />110 <Row label='Expiration:' content={expiration} />111 <Row label='Test size:' content={pushState.exp_size_in_percent + '%'} />112 </div>113 );114 }115 let previewMessage = pushState.data;116 if (isExperiment && pushState.exp_type === 'message') {117 previewMessage = this.state.currentTest === 'Group A' ? pushState.data1 : pushState.data2;118 }119 let previewTime = new Date();120 if (isExperiment && pushState.exp_type === 'time') {121 previewTime = this.state.currentTest === 'Group A' ? pushState.push_time_1_iso : pushState.push_time_2_iso;122 } else if (pushState.push_time_type !== 'now') {123 previewTime = pushState.push_time_iso;124 }125 let previewContent = (126 <VisiblePreview127 isLocal={pushState.local_time}128 type={this.state.currentPreview.toLowerCase().replace(/\s/, '')}129 message={previewMessage}130 time={previewTime || new Date()}131 appName={this.context.currentApp.name}132 fade={isExperiment} />133 );134 if (!isExperiment && pushState.data_type === 'json') {135 previewContent = null;136 } else if (isExperiment) {137 if (this.state.currentTest === 'Group A' && pushState.data_type_1 === 'json') {138 previewContent = null;139 } else if (this.state.currentTest === 'Group B' && pushState.data_type_2 === 'json') {140 previewContent = null;141 }142 }143 return (144 <div className={styles.wrap}>145 <div className={styles.left}>146 <div className={styles.section}>147 <div className={styles.title}>Audience</div>148 <Row label='Sending to:' content={audienceName + (count > -1 ? ` (${count} devices)` : '')} />149 </div>150 {messagePreview}151 {timePreview}152 </div>153 <div className={styles.right}>154 {previewContent || <div className={styles.noPreview}>No Preview</div>}155 {previewContent ?156 <div className={styles.typeSelect}>157 <SegmentSelect158 values={['iOS', 'Android', 'OS X', 'Windows']}159 current={this.state.currentPreview}160 onChange={(currentPreview) => this.setState({ currentPreview })} />161 </div> : null}162 {isExperiment ?163 <div className={styles.testSelect}>164 <SegmentSelect165 values={['Group A', 'Group B']}166 current={this.state.currentTest}167 onChange={(currentTest) => this.setState({ currentTest })} />168 </div> : null}169 </div>170 </div>171 );172 }173}174PushPreview.contextTypes = {175 currentApp: React.PropTypes.instanceOf(ParseApp)...
PushstateHelper.js
Source:PushstateHelper.js
...78 e.stopImmediatePropagation();79 if(o.use_hash){80 window.location.hash = _href;81 } else {82 history.pushState(null, null, _href);83 }84 fn.statechange(_href, _data);85 }86 } else if($t.hasClass('js-simulate-pushstate')) {87 e.stopImmediatePropagation();88 fn.statechange(_href, _data);89 } else if($t.hasClass('js-do-popstate')) {90 e.stopImmediatePropagation();91 history.back();92 }93 },94 popstate: function(e, d) {95 if(o.use_hash){96 fn.statechange(window.location.hash, d);97 } else {98 fn.statechange(window.location.pathname, d);99 }100 },101 pushstate: function(e, d) {102 if(o.use_hash){103 if(window.location.hash != d.pathname){104 window.location.hash = d.pathname;105 }106 } else {107 if(window.location.pathname != d.pathname){108 history.pushState(null, null, d.pathname);109 }110 }111 if(!d || !d.prevent_propagation){112 fn.statechange(d.pathname, d);113 }114 },115 simulate_pushstate: function(e, d) {116 if(!d || !d.prevent_propagation){117 fn.statechange(d.pathname, d);118 }119 },120 hashchange: function(e, d) {121 if (!d || !d.prevent_propagation) {122 fn.statechange(window.location.hash);...
routes.js
Source:routes.js
1routes = [2 {3 path: '/',4 id: 'home',5 url: './pages/homepage.html',6 pushState: true7 },8 {9 path: '/about/',10 url: './pages/about.html',11 pushState: true12 },13 //<editor-fold desc="mHBS Guide Routes" defaultstate="collapsed">14 {15 path: '/testvideo/',16 url: './pages/testvideo.html'17 },18 {19 path: '/page1/',20 url: './pages/page1.html',21 pushState: true22 },23 {24 path: '/section1/',25 url: './pages/section1.html',26 pushState: true27 },28 {29 path: '/section1a/',30 url: './pages/section1a.html',31 pushState: true32 },33 {34 path: '/section1b/',35 url: './pages/section1b.html',36 pushState: true37 },38 {39 path: '/section1c/',40 url: './pages/section1c.html',41 pushState: true42 },43 {44 path: '/section2/',45 url: './pages/section2.html',46 pushState: true47 },48 {49 path: '/section2a/',50 url: './pages/section2a.html',51 pushState: true52 },53 {54 path: '/section2b/',55 url: './pages/section2b.html',56 pushState: true57 },58 {59 path: '/section2c/',60 url: './pages/section2c.html',61 pushState: true62 },63 {64 path: '/section2d/',65 url: './pages/section2d.html',66 pushState: true67 },68 {69 path: '/section2e/',70 url: './pages/section2e.html',71 pushState: true72 },73 {74 path: '/section3/',75 url: './pages/section3.html',76 pushState: true77 },78 {79 path: '/section3a/',80 url: './pages/section3a.html',81 pushState: true82 },83 {84 path: '/section3b/',85 url: './pages/section3b.html',86 pushState: true87 },88 {89 path: '/section3c/',90 url: './pages/section3c.html',91 pushState: true92 },93 {94 path: '/section3d/',95 url: './pages/section3d.html',96 pushState: true97 },98 {99 path: '/section3e/',100 url: './pages/section3e.html',101 pushState: true102 },103 {104 path: '/section3f/',105 url: './pages/section3f.html',106 pushState: true107 },108 {109 path: '/section3g/',110 url: './pages/section3g.html',111 pushState: true112 },113 {114 path: '/section4/',115 url: './pages/section4.html',116 pushState: true117 },118 {119 path: '/section4a/',120 url: './pages/section4a.html',121 pushState: true122 },123 {124 path: '/section4b/',125 url: './pages/section4b.html',126 pushState: true127 },128 {129 path: '/section4c/',130 url: './pages/section4c.html',131 pushState: true132 },133 {134 path: '/section4d/',135 url: './pages/section4d.html',136 pushState: true137 },138 {139 path: '/section4e/',140 url: './pages/section4e.html',141 pushState: true142 },143 {144 path: '/section5/',145 url: './pages/section5.html',146 pushState: true147 },148 {149 path: '/section5a/',150 url: './pages/section5a.html',151 pushState: true152 },153 {154 path: '/section5b',155 url: './pages/section5b.html',156 pushState: true157 },158 {159 path: '/section6/',160 url: './pages/section6.html',161 pushState: true162 },163 {164 path: '/section6a/',165 url: './pages/section6a.html',166 pushState: true167 },168 {169 path: '/section6b/',170 url: './pages/section6b.html',171 pushState: true172 },173 {174 path: '/section6c/',175 url: './pages/section6c.html',176 pushState: true177 },178 {179 path: '/section6d/',180 url: './pages/section6d.html',181 pushState: true182 },183 {184 path: '/section6e/',185 url: './pages/section6e.html',186 pushState: true187 },188 {189 path: '/section7/',190 url: './pages/section7.html',191 pushState: true192 },193 //</editor-fold>194 {195 path: '/mhbsmain/',196 id: 'mhbsmain',197 url: './pages/mhbsmain.html',198 pushState: true199 },200 {201 path: '/videoList/',202 id: 'videoList',203 pushState: true,204 on: {205 pageBeforeIn: function (event, page) {206 /*207 console.log(event);208 // Router instance209 var router = this;210 // App instance211 var app = router.app;212 console.log(event + page);213 app.triggerOnlineContent();214 */215 }216 },217 async: function (routeTo, routeFrom, resolve, reject) {218 // Router instance219 var router = this;220 // App instance221 var app = router.app;222 if (app.data.videoList.length > 0) {223 resolve({224 componentUrl: './pages/videoList.html'225 });226 }227 else {228 if (app.data.offlineMode) {229 alert("Please activate wifi to download content");230 } else {231 app.methods.triggerOnlineContent();232 }233 reject({234 url: routeFrom235 })236 }237 }238 },239 // privacy policy route240 {241 path: '/privacypolicy',242 url: './pages/privacypolicy.html',243 pushState: true244 },245 // Default route (404 page). MUST BE THE LAST246 {247 path: '(.*)',248 url: './pages/404.html',249 pushState: true250 },...
pushstate.js
Source:pushstate.js
...11 },12 set: state => {13 var base = state.startsWith('/') ? PushState.root : document.location.pathname + '/';14 // console.log('state',state,push);15 history.pushState(null, null, base + PushState.clean(state));16 },17 get: () => {18 return '/' + PushState.clean((document.location.pathname+'/').replace(PushState.root, ''))19 },20 clean: p => p.split('/').filter(v => v).join('/'),21 event: (type, source = window) =>22 source.dispatchEvent(new CustomEvent("stateChange", {23 detail: {24 // state: document.location.pathname,25 type: type26 },27 bubbles: true28 })),29 match: (node, attr) => {...
blog.pushstate.js
Source:blog.pushstate.js
1/**2 * @file3 * This file activates the AJAX navigation.4 *5 * The blog can load pages and posts via AJAX for faster navigation on the6 * site. It uses pushState to update the page navigation.7 */8(function( document, blog ) {9 blog.pushState = blog.pushState || {};10 // Activate the links in the provided context for PushState.11 blog.pushState.activateLinks = function( context ) {12 // We only handle internal links. Links that point to other websites13 // are ignored.14 var links = context.querySelectorAll( 'a[href^="/"]' ),15 ignore = [ '/feed.xml' ];16 for ( var i = links.length - 1; i >= 0; --i ) {17 (function( link ) {18 var href = link.getAttribute( 'href' );19 if ( ignore.indexOf( href ) === -1 ) {20 link.addEventListener( 'click', function( e ) {21 /*e.preventDefault();22 blog.pushState.ajax({23 url: link.href,24 success: function( xhr, e ) {25 xhr.response26 }27 });28 return false;*/29 }, false );30 }31 })( links[ i ] );32 }33 };34 // Provide a simple AJAX mechanism.35 blog.pushState.ajax = function( options ) {36 // We need at least an URL.37 if ( options.url === undefined ) {38 return;39 }40 var defaults = {41 method: 'GET',42 success: function() { /* noop */ },43 error: function() { /* noop */ }44 };45 for ( var setting in defaults ) {46 if ( options[ setting ] === undefined ) {47 options[ setting ] = defaults[ setting ];48 }49 }50 var xhr = new XMLHttpRequest();51 xhr.open( options.method, options.url, true );52 xhr.onload = function( e ) {53 if ( this.status == 200 ) {54 options.success( this, e );55 } else {56 options.error( this, e );57 }58 };59 xhr.send();60 };61 // Initialize the logic.62 blog.pushState.init = function() {63 // Check if the browser is compatible with what we want to do. If not, all64 // the JS enhancements will simply be ignored.65 blog.pushState.isCompatible = blog.pushState.isCompatible || ( document.querySelectorAll && document.body.classList && document.body.classList.add && document.body.classList.remove && history.pushState && XMLHttpRequest !== undefined && typeof new XMLHttpRequest().responseType === 'string' );66 if ( blog.pushState.isCompatible ) {67 // Activate all links in the document scope for PushState fetching.68 blog.pushState.activateLinks( document );69 }70 };...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page._frameManager.networkManager.frameNavigatedPromise(page.mainFrame(), page.mainFrame()._client.send('Page.navigate', {7 frameId: page.mainFrame()._id8 }));9 await page.screenshot({ path: `example.png` });10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 await page.route('**/*', route => {18 if (route.request().url().endsWith('.png') ||19 route.request().url().endsWith('.jpg'))20 route.abort();21 route.continue();22 });23 await page.screenshot({ path: `example.png` });24 await browser.close();25})();26const { chromium } = require('playwright');27(async () => {28 const browser = await chromium.launch();29 const context = await browser.newContext();30 const page = await context.newPage();31 await page.route('**/*', route => {32 if (route.request().url().endsWith('logo.png'))33 route.fulfill({ path: 'my-file.png' });34 route.continue();35 });36 await page.screenshot({ path: `example.png` });37 await browser.close();38})();39const { chromium } = require('playwright');40(async () => {41 const browser = await chromium.launch();42 const context = await browser.newContext();43 const page = await context.newPage();
Using AI Code Generation
1await page.evaluate(() => {2 history.pushState({}, '', '/new-page');3});4await page.evaluate(() => {5 history.replaceState({}, '', '/new-page');6});7const { PlaywrightInternalAPI } = require('playwright-internal-api');8const playwrightInternalAPI = new PlaywrightInternalAPI(page);9await playwrightInternalAPI.pushState({}, '', '/new-page');10await playwrightInternalAPI.replaceState({}, '', '/new-page');11await playwrightInternalAPI.pushState(state, title, url);12await playwrightInternalAPI.replaceState(state, title, url);13MIT © [Rahul Kadyan](
Using AI Code Generation
1const { page } = require('@playwright/test')2await page.evaluate(() => {3 window.history.pushState({}, '', '/new/path')4})5const { page } = require('@playwright/test')6await page.evaluate(() => {7 window.history.replaceState({}, '', '/new/path')8})9const { test, expect } = require('@playwright/test')10const { addHistoryPlugin } = require('playwright-history')11test.use(addHistoryPlugin())12test('test', async ({ page }) => {13 await page.evaluate(() => {14 window.history.pushState({}, '', '/new/path')15 })16})17[MIT](LICENSE)
Using AI Code Generation
1await page.goBack();2await page.goForward();3await page.reload();4- The screenshot() method takes an object as a parameter that contains the following properties:5await page.screenshot({ path: 'screenshot.png' });6- The `emulate()` method takes an object as a parameter that contains the following properties:
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!