fix: proxy detection needs to use session-relative plugins
MODIFY
lib/appium.js
lib/appium.js
@@ -360,16 +360,12 @@ class AppiumDriver extends BaseDriver {
}
/**
- * To get plugins for a command, we either get the plugin instances associated with the
- * particular command's session, or in the case of sessionless plugins, pull from the set of
- * plugin instances reserved for sessionless commands (and we lazily create plugin instances on
- * first use)
+ * Get the appropriate plugins for a session (or sessionless plugins)
*
- * @param {string} cmd - the name of the command to find a plugin to handle
- * @param {string} sessionId - the particular session for which to find a plugin, or null if
- * sessionless
+ * @param {?string} sessionId - the sessionId (or null) to use to find plugins
+ * @returns {Array} - array of plugin instances
*/
- pluginsToHandleCmd (cmd, sessionId) {
+ pluginsForSession (sessionId = null) {
let plugins = [];
if (sessionId) {
if (!this.sessionPlugins[sessionId]) {
@@ -382,9 +378,24 @@ class AppiumDriver extends BaseDriver {
}
plugins = this.sessionlessPlugins;
}
+ return plugins;
+ }
+
+ /**
+ * To get plugins for a command, we either get the plugin instances associated with the
+ * particular command's session, or in the case of sessionless plugins, pull from the set of
+ * plugin instances reserved for sessionless commands (and we lazily create plugin instances on
+ * first use)
+ *
+ * @param {string} cmd - the name of the command to find a plugin to handle
+ * @param {?string} sessionId - the particular session for which to find a plugin, or null if
+ * sessionless
+ */
+ pluginsToHandleCmd (cmd, sessionId = null) {
// to handle a given command, a plugin should either implement that command as a plugin
// instance method or it should implement a generic 'handle' method
- return plugins.filter((p) => _.isFunction(p[cmd]) || _.isFunction(p.handle));
+ return this.pluginsForSession(sessionId)
+ .filter((p) => _.isFunction(p[cmd]) || _.isFunction(p.handle));
}
createPluginInstances (sessionId) {
@@ -553,7 +564,7 @@ class AppiumDriver extends BaseDriver {
return true;
}
// if even just one plugin needs to avoid proxying, do so
- for (const plugin of this.plugins) {
+ for (const plugin of this.pluginsForSession(sessionId)) {
if (plugin.shouldAvoidProxy?.(method, url, body)) {
log.info(`Request to ${url} would normally be proxied, but plugin ${plugin.name} wants ` +
`to handle it internally. We'll avoid proxying in this case.`);

fix: proxy detection needs to use session-relative plugins