8000 fix: reject with error when url not loaded by codebytere · Pull Request #16571 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: reject with error when url not loaded #16571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2019
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
11 changes: 8 additions & 3 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1444,12 +1444,17 @@ v8::Local<v8::Promise> WebContents::HasServiceWorker() {
auto* context = GetServiceWorkerContext(web_contents());
if (!context) {
promise->RejectWithErrorMessage("Unable to get ServiceWorker context.");
return promise->GetHandle();
}

GURL url = web_contents()->GetLastCommittedURL();
if (!url.is_valid()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would a committed url be invalid ? Its a virtual url generated by the navigation controller. The DCHECK you hit is probably the other url that should be encompassed isn't recognized, in which case try using visible URL. Also using the result of committed URL to test page loading state is not a good idea.

promise->RejectWithErrorMessage("URL invalid or not yet loaded.");
return promise->GetHandle();
}

context->CheckHasServiceWorker(
web_contents()->GetLastCommittedURL(),
web_contents()->GetLastCommittedURL(),
base::BindOnce(&OnServiceWorkerCheckDone, promise));
url, url, base::BindOnce(&OnServiceWorkerCheckDone, promise));

return promise->GetHandle();
}
Expand Down
9 changes: 7 additions & 2 deletions spec/api-web-contents-spec.js
< 4248 td id="diff-675d2fdc497df732c76f0d75423e72331a9ffbb4d5c71d9ef792bd209b6edb70L241" data-line-number="241" class="blob-num blob-num-context js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,18 @@ describe('webContents module', () => {
})

describe('ServiceWorker APIs', () => {
it('can successfully register a ServiceWorker', async () => {
it('can successfully check for presence of a ServiceWorker', async () => {
await w.loadFile(path.join(fixtures, 'api', 'service-worker', 'service-worker.html'))
const hasSW = await w.webContents.hasServiceWorker()
expect(hasSW).to.be.true()
})

it('can successfully register a ServiceWorker (callback)', (done) => {
it('throws properly for invalid url', async () => {
const promise = w.webContents.hasServiceWorker()
return expect(promise).to.be.eventually.rejectedWith(Error, 'URL invalid or not yet loaded.')
})

it('can successfully check for presence of a ServiceWorker (callback)', (done) => {
w.loadFile(path.join(fixtures, 'api', 'service-worker', 'service-worker.html')).then(() => {
w.webContents.hasServiceWorker(hasSW => {
expect(hasSW).to.be.true()
Expand Down
0