Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion apps/web/docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ register(options)
### serverPort

- **Description**: CDP server port for Devtool
- **Link**: [devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort}](devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort})
- **Link**: [devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort}](devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort})
- **Default value**: `5271`

### autoOpenDevtool
Expand Down
2 changes: 1 addition & 1 deletion apps/web/docs/zh/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ register(options)
### serverPort

- **描述**: CDP 服务器端口,用于 Devtool
- **链接**: [devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort}](devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort})
- **链接**: [devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort}](devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort})
- **默认值**: `5271`

### autoOpenDevtool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function createCDPMessage(overrides?: Partial<MockCDPMessage>): MockCDPMe
export function createMockRequestOptions(overrides?: Record<string, unknown>) {
return {
method: 'GET',
hostname: 'localhost',
hostname: '127.0.0.1',
port: 80,
path: '/',
headers: {},
Expand Down
26 changes: 13 additions & 13 deletions packages/network-debugger/src/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,50 +255,50 @@ describe('RequestDetail', () => {
})

describe('isHiden', () => {
test('should return true for ws://localhost/ websocket connections', () => {
test('should return true for ws://127.0.0.1/ websocket connections', () => {
const requestDetail = new RequestDetail()
requestDetail.requestHeaders = { Upgrade: 'websocket' }
requestDetail.url = 'ws://localhost/'
requestDetail.url = 'ws://127.0.0.1/'

expect(requestDetail.isHiden()).toBe(true)
})

test('should return true for http://localhost/ websocket connections', () => {
test('should return true for http://127.0.0.1/ websocket connections', () => {
const requestDetail = new RequestDetail()
requestDetail.requestHeaders = { Upgrade: 'websocket' }
requestDetail.url = 'http://localhost/'
requestDetail.url = 'http://127.0.0.1/'

expect(requestDetail.isHiden()).toBe(true)
})

test('should return false for non-localhost websocket connections', () => {
test('should return false for non-127.0.0.1 websocket connections', () => {
const requestDetail = new RequestDetail()
requestDetail.requestHeaders = { Upgrade: 'websocket' }
requestDetail.url = 'ws://example.com/'

expect(requestDetail.isHiden()).toBe(false)
})

test('should return false for non-websocket localhost connections', () => {
test('should return false for non-websocket 127.0.0.1 connections', () => {
const requestDetail = new RequestDetail()
requestDetail.requestHeaders = { 'Content-Type': 'application/json' }
requestDetail.url = 'http://localhost/'
requestDetail.url = 'http://127.0.0.1/'

expect(requestDetail.isHiden()).toBe(false)
})

test('should return false for websocket with different localhost path', () => {
test('should return false for websocket with different 127.0.0.1 path', () => {
const requestDetail = new RequestDetail()
requestDetail.requestHeaders = { Upgrade: 'websocket' }
requestDetail.url = 'ws://localhost/api'
requestDetail.url = 'ws://127.0.0.1/api'

expect(requestDetail.isHiden()).toBe(false)
})

test('should return false for websocket with localhost and port', () => {
test('should return false for websocket with 127.0.0.1 and port', () => {
const requestDetail = new RequestDetail()
requestDetail.requestHeaders = { Upgrade: 'websocket' }
requestDetail.url = 'ws://localhost:8080/'
requestDetail.url = 'ws://127.0.0.1:8080/'

expect(requestDetail.isHiden()).toBe(false)
})
Expand All @@ -311,10 +311,10 @@ describe('RequestDetail', () => {
expect(requestDetail.isHiden()).toBe(false)
})

test('should return false for wss://localhost/ (secure websocket)', () => {
test('should return false for wss://127.0.0.1/ (secure websocket)', () => {
const requestDetail = new RequestDetail()
requestDetail.requestHeaders = { Upgrade: 'websocket' }
requestDetail.url = 'wss://localhost/'
requestDetail.url = 'wss://127.0.0.1/'

expect(requestDetail.isHiden()).toBe(false)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/network-debugger/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class RequestDetail {
}

isHiden() {
return this.isWebSocket() && ['http://localhost/', 'ws://localhost/'].includes(this.url!)
return this.isWebSocket() && ['http://127.0.0.1/', 'ws://127.0.0.1/'].includes(this.url!)
}

isWebSocket() {
Expand Down Expand Up @@ -99,7 +99,7 @@ export interface RegisterOptions {
port?: number
/**
* @description CDP Server Port, used for Devtool
* @link devtools://devtools/bundled/inspector.html?ws=localhost:${serverPort}
* @link devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${serverPort}
* @default 5271
*/
serverPort?: number
Expand Down
4 changes: 2 additions & 2 deletions packages/network-debugger/src/core/fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ export class MainProcess {
unlinkSafe(lockFilePath)
}
fs.writeFileSync(lockFilePath, `${process.pid}`)
const socket = new WebSocket(`ws://localhost:${props.port}`)
const socket = new WebSocket(`ws://127.0.0.1:${props.port}`)
socket.on('open', () => {
unlinkSafe(lockFilePath)
resolve(socket)
})
socket.on('error', () => {
this.openProcess(() => {
unlinkSafe(lockFilePath)
const socket = new WebSocket(`ws://localhost:${props.port}`)
const socket = new WebSocket(`ws://127.0.0.1:${props.port}`)
socket.on('open', () => {
resolve(socket)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/network-debugger/src/core/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ describe('core/request.ts', () => {
mockMainProcess as never
)

// 使用 localhost 的隐藏 URL
// 使用 127.0.0.1 的隐藏 URL
const options: RequestOptions = {
hostname: 'localhost',
hostname: '127.0.0.1',
path: '/',
method: 'GET',
headers: {
Expand Down
4 changes: 2 additions & 2 deletions packages/network-debugger/src/fork/devtool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class DevtoolServer extends BaseDevtoolServer implements IDevtoolServer {
}

public async open() {
const url = `devtools://devtools/bundled/inspector.html?ws=localhost:${this.port}`
const url = `devtools://devtools/bundled/inspector.html?ws=127.0.0.1:${this.port}`
try {
if (IS_DEV_MODE) {
log(`In dev mode, open chrome devtool manually: ${url}`)
Expand Down Expand Up @@ -90,7 +90,7 @@ export class DevtoolServer extends BaseDevtoolServer implements IDevtoolServer {
}
try {
count++
resolve((await fetch(`http://localhost:${REMOTE_DEBUGGER_PORT}/json`)).json())
resolve((await fetch(`http://127.0.0.1:${REMOTE_DEBUGGER_PORT}/json`)).json())
clearInterval(stop)
} catch {
// ignore
Expand Down