Skip to content

Commit

Permalink
do not use window.history if inside iframe (#3437)
Browse files Browse the repository at this point in the history
* do not use window.history if inside iframe

* Move security related test cases into a its own file.

* Removes the unused renderScript function

* Add a nerv example. (#3573)

* Add a nerv example.

* Fix for indentation/style

* Fix for name

* warn user about browser history if next.js used in iframe
  • Loading branch information
Henric Malmberg authored and timneutkens committed Feb 4, 2018
1 parent 3bbfbfa commit b8f189f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/router/router.js
Expand Up @@ -4,7 +4,7 @@ import { parse, format } from 'url'
import EventEmitter from '../EventEmitter'
import shallowEquals from '../shallow-equals'
import PQueue from '../p-queue'
import { loadGetInitialProps, getURL } from '../utils'
import { loadGetInitialProps, getURL, warn, execOnce } from '../utils'
import { _notifyBuildIdMismatch, _rewriteUrlForNextExport } from './'

export default class Router {
Expand Down Expand Up @@ -185,7 +185,9 @@ export default class Router {
}

changeState (method, url, as, options = {}) {
if (method !== 'pushState' || getURL() !== as) {
if (window.frameElement) {
execOnce(warn)(`Warning: You're using Next.js inside an iFrame. Browser history is disabled.`)
} else if (method !== 'pushState' || getURL() !== as) {
window.history[method]({ url, as, options }, null, as)
}
}
Expand Down

0 comments on commit b8f189f

Please sign in to comment.