Finally made Pipe2Goose work. Here is how:
1. In pipe2Goose.js, we first get all the tabs, and pass them to background.js. Then we inject code into each tab to call the pipe2search function, which returns tabid as well as whether the page is a PIPE2 page to gaggle.js through a custom event.

2. gaggle.js checks whether none of the tabs is a PIPE2 page. If so, open a new tab with the url of PIPE2. pipe2Goose.js will be injected since it is a content script. Its scanPage function fetches the data from background.js, then inject code to call pipe2SearchWithTimer. Once the function returns, it passes the data to the page through a custom event.

3. Otherwise, if one of the pages is a Pipe2 page, we simply pass the data to the page through a custom event, and activate the tab.