Skip to content

Commit

Permalink
Fix chrome.windows.create API not working (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto authored Jun 28, 2024
1 parent b5c1269 commit b0391db
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,26 @@ describe('transformSource Tests', () => {
expect(firstArg.type).toBe('CallExpression')
expect(firstArg.callee.name).toBe('r.solve')
})

// https://developer.chrome.com/docs/extensions/reference/api/windows#property-create-createData-url
test('should transform chrome.windows.create when URL argument is an array', () => {
const code = `chrome.windows.create({url: ['https://www.extension.js.org/']})`
const ast = parse(code)
transformSource(ast, code)
// Check if the first argument of the first expression is a call to resolveString
const firstArg = (ast.program.body[0] as any).expression.arguments[0]
expect(firstArg.type).toBe('CallExpression')
expect(firstArg.callee.name).toBe('r.solve')
})

test('should transform chrome.windows.create when URL argument is a string', () => {
const code = `chrome.windows.create({url: 'https://www.extension.js.org/'})`
const ast = parse(code)
transformSource(ast, code)
// Check if the first argument of the first expression is a call to resolveString
const firstArg = (ast.program.body[0] as any).expression.arguments[0]
expect(firstArg.type).toBe('CallExpression')
expect(firstArg.callee.name).toBe('r.solve')
})
})

8 changes: 6 additions & 2 deletions packages/resolve-plugin/resolver-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ function solve(apiArgument?: SolveType) {
// chrome.tabs.create({..., url: string})
// chrome.tabs.executeScript({..., url: string})
// chrome.tabs.insertCSS({..., url: string})
// chrome.windows.create({..., url: string})
...(obj?.url && {url: resolver(obj.url)}),
// chrome.windows.create({..., url: string || string[]})
...(obj?.url && {
url: Array.isArray(obj?.url)
? obj?.url.map((currentUrl: string) => resolver(currentUrl))
: resolver(obj?.url)
}),

// chrome.notifications.create
// https://developer.chrome.com/docs/extensions/reference/api/notifications#property-NotificationOptions-iconUrl
Expand Down

0 comments on commit b0391db

Please sign in to comment.