const STACK_START = /^\s+at /

const STACKTRACE_FILTER = [
    // exclude @wdio/sync from stack traces
    'node_modules/@wdio/sync/',

    // exclude middlewares
    'node_modules/webdriverio/build/middlewares.js',

    // exclude Request emit
    ' (events.js:',
    ' (domain.js:',

    // other excludes
    '(internal/process/next_tick.js',
    'new Promise (<anonymous>)',
    'Generator.next (<anonymous>)',
    '__awaiter ('
]

/**
 * filter stack array
 * @param {string} stackRow
 * @returns {boolean}
 */
export const STACKTRACE_FILTER_FN = (stackRow) => {
    if (stackRow.match(STACK_START)) {
        return !STACKTRACE_FILTER.some(r => stackRow.includes(r))
    }
    return true
}

@@ -144,25 +144,38 @@
 exclude 
-middlewar
+webdriverio stack trac
 es%0A    '
@@ -209,22 +209,8 @@
 ild/
-middlewares.js
 ',%0A%0A

Cleanup stacktraces (#3750)