Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: live preview not working on chrome v111 #263

Merged
merged 2 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 21 additions & 33 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ define(function LiveDevelopment(require, exports, module) {
* Handles of registered servers
*/
var _regServers = [];

PreferencesManager.definePreference("livedev.wsPort", "number", 8125, {
description: Strings.DESCRIPTION_LIVEDEV_WEBSOCKET_PORT
});

PreferencesManager.definePreference("livedev.enableReverseInspect", "boolean", true, {
description: Strings.DESCRIPTION_LIVEDEV_ENABLE_REVERSE_INSPECT
});
Expand Down Expand Up @@ -1136,10 +1136,9 @@ define(function LiveDevelopment(require, exports, module) {
_openDeferred.reject();
}

function _openInterstitialPage() {
function _establishConnection() {
var browserStarted = false,
retryCount = 0;

// Open the live browser if the connection fails, retry 3 times
Inspector.connectToURL(launcherUrl).fail(function onConnectFail(err) {
if (err === "CANCEL") {
Expand Down Expand Up @@ -1203,34 +1202,6 @@ define(function LiveDevelopment(require, exports, module) {
}
retryCount++;

if (!browserStarted && exports.status !== STATUS_ERROR) {
NativeApp.openLiveBrowser(
launcherUrl,
true // enable remote debugging
)
.done(function () {
browserStarted = true;
})
.fail(function (err) {
var message;

_setStatus(STATUS_ERROR);
if (err === FileSystemError.NOT_FOUND) {
message = Strings.ERROR_CANT_FIND_CHROME;
} else {
message = StringUtils.format(Strings.ERROR_LAUNCHING_BROWSER, err);
}

Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_LAUNCHING_BROWSER_TITLE,
_makeTroubleshootingMessage(message)
);

_openDeferred.reject("OPEN_LIVE_BROWSER");
});
}

if (exports.status !== STATUS_ERROR) {
window.setTimeout(function retryConnect() {
Inspector.connectToURL(launcherUrl).fail(onConnectFail);
Expand All @@ -1239,6 +1210,23 @@ define(function LiveDevelopment(require, exports, module) {
});
}

function _openInterstitialPage() {
NativeApp.openLiveBrowser(launcherUrl)
.done(_establishConnection)
.fail((err)=>{
var message;
_setStatus(STATUS_ERROR);
message = StringUtils.format(Strings.ERROR_LAUNCHING_BROWSER, err);
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_LAUNCHING_BROWSER_TITLE,
_makeTroubleshootingMessage(message)
);

_openDeferred.reject("OPEN_LIVE_BROWSER");
});
}

// helper function that actually does the launch once we are sure we have
// a doc and the server for that doc is up and running.
function _doLaunchAfterServerReady(initialDoc) {
Expand Down Expand Up @@ -1383,7 +1371,7 @@ define(function LiveDevelopment(require, exports, module) {
.done(function () {
var reverseInspectPref = PreferencesManager.get("livedev.enableReverseInspect"),
wsPort = PreferencesManager.get("livedev.wsPort");

if (wsPort && reverseInspectPref) {
WebSocketTransport.createWebSocketServer(wsPort);
}
Expand Down
5 changes: 5 additions & 0 deletions src/LiveDevelopment/MultiBrowserImpl/launchers/Launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ define(function (require, exports, module) {
_nodeDomain.exec("launch", url);
}

function launchChromeWithRDP(url) {
return _nodeDomain.exec("launchChromeWithRDP", url);
}

// Exports
exports.launch = launch;
exports.launchChromeWithRDP = launchChromeWithRDP;

});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ function _cmdLaunch(url) {
open(url);
}

function _launchChromeWithRDP(url, enableRemoteDebugging) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open(url, {app: ['chrome',
"--disk-cache-size=250000000",
"--no-first-run",
"--no-default-browser-check",
"--disable-default-apps",
"--allow-file-access-from-files",
"--remote-debugging-port=9222",
"--user-data-dir=%appdata%/lp",
"--remote-allow-origins=*"
]});
}

/**
* Initializes the domain and registers commands.
Expand All @@ -65,6 +77,19 @@ function init(domainManager) {
],
[]
);

domainManager.registerCommand(
"launcher", // domain name
"launchChromeWithRDP", // command name
_launchChromeWithRDP, // command handler function
false, // this command is synchronous in Node
"Launches a given HTML file in the browser for live development",
[
{ name: "url", type: "string", description: "file:// url to the HTML file" },
{ name: "enableRemoteDebugging", type: "string", description: "enable remote debugging or not"}
],
[]
);
}

exports.init = init;
22 changes: 4 additions & 18 deletions src/utils/NativeApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ define(function (require, exports, module) {
"use strict";

var Async = require("utils/Async"),
FileSystemError = require("filesystem/FileSystemError");
FileSystemError = require("filesystem/FileSystemError"),
DefaultLauncher = require("LiveDevelopment/MultiBrowserImpl/launchers/Launcher");

/**
* @private
Expand All @@ -45,25 +46,10 @@ define(function (require, exports, module) {
/** openLiveBrowser
* Open the given URL in the user's system browser, optionally enabling debugging.
* @param {string} url The URL to open.
* @param {boolean=} enableRemoteDebugging Whether to turn on remote debugging. Default false.
* @return {$.Promise}
*/
function openLiveBrowser(url, enableRemoteDebugging) {
var result = new $.Deferred();

brackets.app.openLiveBrowser(url, !!enableRemoteDebugging, function onRun(err, pid) {
if (!err) {
// Undefined ids never get removed from list, so don't push them on
if (pid !== undefined) {
liveBrowserOpenedPIDs.push(pid);
}
result.resolve(pid);
} else {
result.reject(_browserErrToFileError(err));
}
});

return result.promise();
function openLiveBrowser(url) {
return DefaultLauncher.launchChromeWithRDP(url);
}

/** closeLiveBrowser
Expand Down