From e7ec9e8ea7faf16820218f1211d5a2590490c41b Mon Sep 17 00:00:00 2001 From: Zach Bloomquist Date: Tue, 5 Mar 2019 11:30:29 -0500 Subject: [PATCH] Don't show "Restore Pages" prompt (#3619) Fixes #2048 --- packages/server/lib/browsers/chrome.coffee | 26 +++++++++++++++---- .../test/unit/browsers/chrome_spec.coffee | 19 ++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/server/lib/browsers/chrome.coffee b/packages/server/lib/browsers/chrome.coffee index 6eabd9194afc..61a1e82fc9cb 100644 --- a/packages/server/lib/browsers/chrome.coffee +++ b/packages/server/lib/browsers/chrome.coffee @@ -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 @@ -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 @@ -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) @@ -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}") diff --git a/packages/server/test/unit/browsers/chrome_spec.coffee b/packages/server/test/unit/browsers/chrome_spec.coffee index a8126c45b9ee..233a95eb6f63 100644 --- a/packages/server/test/unit/browsers/chrome_spec.coffee +++ b/packages/server/test/unit/browsers/chrome_spec.coffee @@ -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", -> @@ -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")