Skip to content

Commit

Permalink
Don't show "Restore Pages" prompt (#3619)
Browse files Browse the repository at this point in the history
Fixes #2048
  • Loading branch information
flotwig committed Mar 5, 2019
1 parent 0a87734 commit e7ec9e8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
26 changes: 21 additions & 5 deletions packages/server/lib/browsers/chrome.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defaultArgs = [
"--disable-device-discovery-notifications"

## https://github.com/cypress-io/cypress/issues/2376
"--autoplay-policy=no-user-gesture-required"
"--autoplay-policy=no-user-gesture-required"

## http://www.chromium.org/Home/chromium-security/site-isolation
## https://github.com/cypress-io/cypress/issues/1951
Expand Down Expand Up @@ -109,6 +109,22 @@ _removeRootExtension = ->
.removeAsync(appData.path("extensions"))
.catchReturn(null) ## noop if doesn't exist fails for any reason

## https://github.com/cypress-io/cypress/issues/2048
_disableRestorePagesPrompt = (userDir) ->
prefsPath = path.join(userDir, "Default", "Preferences")

fs.readJson(prefsPath)
.then (preferences) ->
if profile = preferences.profile
if profile["exit_type"] != "Normal" or profile["exited_cleanly"] isnt true
debug("cleaning up unclean exit status")

profile["exit_type"] = "Normal"
profile["exited_cleanly"] = true

fs.writeJson(prefsPath, preferences)
.catch ->

module.exports = {
_normalizeArgExtensions

Expand Down Expand Up @@ -161,12 +177,14 @@ module.exports = {
## https://github.com/cypress-io/cypress/issues/1872
if majorVersion >= CHROME_VERSION_INTRODUCING_PROXY_BYPASS_ON_LOOPBACK
args.push("--proxy-bypass-list=<-loopback>")

args

open: (browser, url, options = {}, automation) ->
{ isTextTerminal } = options

userDir = utils.getProfileDir(browser, isTextTerminal)

Promise
.try =>
args = @_getArgs(options)
Expand All @@ -186,16 +204,14 @@ module.exports = {
options.proxyUrl,
options.socketIoRoute
),

_removeRootExtension(),
_disableRestorePagesPrompt(userDir),
])
.spread (extDest) ->
## normalize the --load-extensions argument by
## massaging what the user passed into our own
args = _normalizeArgExtensions(extDest, args)

userDir = utils.getProfileDir(browser, isTextTerminal)

## this overrides any previous user-data-dir args
## by being the last one
args.push("--user-data-dir=#{userDir}")
Expand Down
19 changes: 19 additions & 0 deletions packages/server/test/unit/browsers/chrome_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension = require("@packages/extension")
plugins = require("#{root}../lib/plugins")
utils = require("#{root}../lib/browsers/utils")
chrome = require("#{root}../lib/browsers/chrome")
fs = require("#{root}../lib/util/fs")

describe "lib/browsers/chrome", ->
context "#open", ->
Expand Down Expand Up @@ -79,6 +80,24 @@ describe "lib/browsers/chrome", ->
"--disk-cache-dir=/profile/dir/CypressCache"
])

it "cleans up an unclean browser profile exit status", ->
sinon.stub(fs, "readJson").withArgs("/profile/dir/Default/Preferences").resolves({
profile: {
exit_type: "Abnormal"
exited_cleanly: false
}
})
sinon.stub(fs, "writeJson")

chrome.open("chrome", "http://", {}, {})
.then ->
expect(fs.writeJson).to.be.calledWith("/profile/dir/Default/Preferences", {
profile: {
exit_type: "Normal"
exited_cleanly: true
}
})

context "#_getArgs", ->
it "disables gpu when linux", ->
sinon.stub(os, "platform").returns("linux")
Expand Down

0 comments on commit e7ec9e8

Please sign in to comment.