Skip to content

Commit

Permalink
Merge branch '2.0-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gegehprast committed Jan 12, 2020
2 parents 5d18a7f + b9a8388 commit 942e5c7
Show file tree
Hide file tree
Showing 62 changed files with 3,029 additions and 3,202 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ before_install:
before_script:
- echo -e "Host $REMOTE_ADDRESS\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
after_success:
- bash deploy.sh
- bash deploy.sh
40 changes: 31 additions & 9 deletions services/Browser.js → Browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ class Browser {
}

/**
* Create new disabled asset page.
* Create new optimized asset page.
*/
async newOptimizedPage() {
const page = await this.browser.newPage()
page.setDefaultTimeout(60000)
await page.setRequestInterception(true)

page.on('request', (req) => {
Expand All @@ -46,10 +47,31 @@ class Browser {
const { browserContextId } = await this.browser._connection.send('Target.createBrowserContext')
const page = await this.browser._createPageInContext(browserContextId)
page.browserContextId = browserContextId
page.setDefaultTimeout(60000)

page.on('request', (req) => {
if (req.resourceType() == 'stylesheet' || req.resourceType() == 'font' || req.resourceType() == 'image') {
req.abort()
} else {
req.continue()
}
})

return page
}

/**
* Get new tab page instance.
* @param page current page.
*/
async getNewTabPage(page) {
const pageTarget = page.target()
const newTarget = await this.browser.waitForTarget(target => target.opener() === pageTarget)
const newPage = await newTarget.page()

return newPage
}

/**
* Close a page, use this function to close a page that has context.
*
Expand All @@ -68,26 +90,26 @@ class Browser {
* Wait for a selector and then return one element
* of that selector.
*
* @param {Object} element Element handle
* @param {Object} page Browser page
* @param {String} selector Selector
*/
async waitAndGetSelector(element, selector) {
await element.waitForSelector(selector)
async $waitAndGet(page, selector) {
await page.waitForSelector(selector)

return await element.$(selector)
return await page.$(selector)
}

/**
* Wait for a selector and then return all element
* of that selector.
*
* @param {Object} element Element handle
* @param {Object} page Browser page
* @param {String} selector Selector
*/
async waitAndGetSelectors(element, selector) {
await element.waitForSelector(selector)
async $$waitAndGet(page, selector) {
await page.waitForSelector(selector)

return await element.$$(selector)
return await page.$$(selector)
}

/**
Expand Down
695 changes: 21 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

Loading

0 comments on commit 942e5c7

Please sign in to comment.